Complete the code to export a value from a CloudFormation stack output.
Outputs:
MyBucketName:
Value: !Ref MyBucket
Export:
Name: [1]The export name must be a unique string used to reference this output in other stacks. Here, using the output logical name MyBucketName as the export name is a common practice.
Complete the code to import an exported value from another CloudFormation stack.
Resources:
MyBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !ImportValue [1]The !ImportValue function requires the exact export name defined in the other stack's outputs. Here, it matches the export name MyBucketName.
Fix the error in the output export name to make it valid for cross-stack reference.
Outputs:
MyBucketArn:
Value: !GetAtt MyBucket.Arn
Export:
Name: [1]Export names must be alphanumeric or include hyphens and underscores but cannot contain spaces or special characters like exclamation marks. MyBucket_Arn is valid.
Fill both blanks to correctly export and import a VPC ID between stacks.
Outputs:
VPCId:
Value: !Ref MyVPC
Export:
Name: [1]
Resources:
MySubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !ImportValue [2]The export and import names must match exactly. Here, the export name is MyApp-VPC and the import uses the same string.
Fill all three blanks to export an RDS instance endpoint and import it in another stack.
Outputs:
DBEndpoint:
Value: !GetAtt MyDB.Endpoint.Address
Export:
Name: [1]
Resources:
MyAppDBConnection:
Type: AWS::RDS::DBInstance
Properties:
DBInstanceIdentifier: mydb
EndpointAddress: !ImportValue [2]
Port: [3]The export and import names must match exactly (MyApp-DBEndpoint). The port 3306 is the default for MySQL RDS instances.