A CloudFormation output exposes a value from a resource created by a template. Unlike a parameter, which supplies a value to the template, an output returns one, such as an EC2 instance’s public name. section 4.5.1
Declare outputs in the template’s Outputs section. Set each output’s Value directly or derive it from a resource with !Ref or !GetAtt; a Description can explain what the value represents. section 4.5.1
Expose an EC2 instance ID and public name
Outputs: ID: Value: !Ref Server Description: 'ID of the EC2 instance' PublicName: Value: !GetAtt 'Server.PublicDnsName' Description: 'Public name of the EC2 instance' section 4.5.1
Resources:
# [...]
InstanceSecurityGroup: #1
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'vm'
VpcId: !Ref VPC
Instance: #2
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !FindInMap [RegionMap, !Ref 'AWS::Region', AMI]
InstanceType: 't2.micro'
IamInstanceProfile: !Ref InstanceProfile
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeleteOnTermination: true
DeviceIndex: 0
GroupSet:
- !Ref InstanceSecurityGroup
SubnetId: !Ref SubnetA
Outputs:
InstanceId: #3
Value: !Ref Instance
Description: 'EC2 Instance ID (connect via Session Manager)'
CacheAddress: #4
Value: !GetAtt 'Cache.RedisEndpoint.Address'
Description: 'Redis DNS name (resolves to a private IP address)'
See outputs that expose an EC2 instance ID and a cache address for use when connecting to a Redis cluster. section 11.1.2
