Lab 05: Outputs


In this lab you will learn about Outputs. Outputs enable you to get access to information about resources within a stack. For example, you can output an EC2 instance’s Public DNS name once it is created.

Furthermore, output values can be imported into other stacks. These are known as cross-stack references.

YAML Syntax:

The Outputs section consists of the key name Outputs, followed by a colon.

  Logical ID:
    Description: Information about the value
    Value: Value to return
      Name: Value to export

You can declare a maximum of 60 outputs in a template.

Topics Covered

In this Lab, you will:

  • Create an Output section in your template and return Public DNS name of the instance.
  • Create Elastic IP resource and attach it to the EC2 instance.
  • Learn how to view outputs form within CloudFormation in AWS console.

Start Lab

  1. Go to the code/20-cloudformation-features/ directory.

  2. Open the 07-lab05-Outputs.yaml file.

  3. Copy the code as you go through the topics below.

    To get the PublicDnsName of the instance, you will need to use Fn::GetAtt intrinsic function. Let’s first check the AWS Documentation for available attributes. You can see that PublicDnsName is valid return value for Fn::GetAtt function.

    Add the section below to your template:

        Description: 'Public DNS of EC2 instance'
        Value: !GetAtt WebServerInstance.PublicDnsName
  4. Go to the AWS console and update your stack with a new template.

    How do I update a Stack?

  5. View the output value on the AWS CloudFormation console, in the Outputs tab.

    How to view Outputs?


In this exercise, you should assign an Elastic IP to your EC2 instance. Then, add an output of the Elastic IP to the Outputs section of the template. You should continue using the 07-lab05-Outputs.yaml template.

  1. Create an AWS::EC2::EIP resource and attach it to your existing EC2 instance.
  2. Create a logical ID called ElasticIP and add it to the Outputs section of the template.
  3. Update the stack to test changes in your template.
Need a hint?
Want to see the solution?


Great work! You have now successfully learned how to use Outputs in CloudFormation template.