Skip to main content
In this lesson you’ll add tags to an EC2 instance resource and expose useful values (the instance ID and its public IP) through AWS CloudFormation Outputs so they appear in the stack outputs. Why this matters:
  • Tags help you identify and organize resources in the AWS console and via automation.
  • Outputs let you export important values from a stack so other stacks, tools, or users can consume them easily.
Steps (high level)
  1. Open your CloudFormation template and find the EC2 instance resource.
  2. Under the instance’s Properties, add a Tags block (for example: Name: SimpleWebServer).
  3. Add an Outputs section at the bottom of the template to expose the instance ID and public IP.
  4. Update the stack with the revised template and verify the tag and outputs in the console.
Use !Ref to return the logical resource reference (for EC2 this gives the instance ID). Use !GetAtt to fetch resource attributes such as the public IP (.PublicIp).
Example — add Tags to the instance and expose Outputs
After updating the template, update your stack (replace the template with the revised one and submit the change). The update process can take a few minutes.
A screenshot of the AWS CloudFormation console on the "Specify stack details" step, showing a Parameters panel with MyInstanceType set to "t3.micro." The left sidebar shows the update stack progress steps and there's a highlighted "Next" button at the bottom right.
When the update completes:
  • Confirm the tag was applied to the instance (check the EC2 Instances page or resource Tags).
  • Open the stack Outputs to see both InstanceId and InstancePublicIP.
The Outputs pane displays the exported instance ID and public IP — the output names mirror the keys we defined (InstanceId, InstancePublicIP).
Screenshot of the AWS CloudFormation console showing a stack named "DemoStack" (status UPDATE_COMPLETE). The Outputs pane lists an EC2 InstanceId and its public IP address.
You can also verify the public IP directly on the EC2 Instances page; the Public IPv4 address should match the value shown in the stack Outputs.
Screenshot of the AWS EC2 Instances page showing a running instance named "SimpleWebServer." The t3.micro instance (i-066a056161fbde943) has public IP 18.191.29.155 and shows 3/3 status checks passed.
Reference: combining attribute functions and joins The pattern used for the EC2 public IP (!GetAtt) can be applied to other resources. For example, to export an S3 bucket ARN and construct a combined label using !Join:
Quick reference table Recap
  • Add Tags under the EC2 instance Properties to label resources (for example, Name: SimpleWebServer).
  • Use Outputs with !Ref to return resource identifiers (InstanceId) and !GetAtt to return attributes (InstancePublicIP).
  • Update the CloudFormation stack and verify tags and outputs in the console.
Links and references

Watch Video