The Complete CloudFormation Guide: Outputs
Table of Contents
- Introduction
- What Are We Doing?
- The Video: Outputs
- The Template So Far: Final Version
- Next Steps
- The Complete CloudFormation Guide Index
Introduction
We are now on our last piece of template anatomy: Outputs. When used on its own, all Outputs do is show up in the console but in this video we'll see how they're used for cross-stack references, so how you can use resources from one template in another one. With this, we will have covered all of our top nine properties of AWS CloudFormation template anatomy!
In the next and final series post, we will relaunch our template with all of the new awesome changes we've made throughout the series thus far and we'll discuss what the next best steps are for your learning journey.
What Are We Doing?
In this video, we'll create an Outputs section at the end of our AWS CloudFormation template to round out the series. We'll set it up with a logical ID, description, and value, as well as discuss what this value can be. Also we'll bring in some old friends (pseudo parameters and intrinsic functions) to round it out. Then we're done!
The Video: Outputs
The Template So Far: Final Version
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description": "A CFN template for learning",
"Metadata": {
"Author": { "Ref": "ParamAuthorName" }
},
"Parameters": {
"ParamAuthorName": {
"Type": "String",
"Description": "Owner of the CFN Template."
},
"ParamAllowSSHFromRange": {
"Type": "String",
"Description": "IP CidrBlock to allow SSH access. i.e. 100.100.100.100/32",
"Default": "0.0.0.0/0"
},
"ParamAllowSSHAccess": {
"Type": "String",
"Default": "true",
"AllowedValues": ["true", "false"],
"ConstraintDescription":"Whether to allow SSH access into the EC2 server"
}
},
"Conditions": {
"AllowSSHAccess": {
"Fn::Equals": [{ "Ref": "ParamAllowSSHAccess" }, "true"]
}
},
"Resources": {
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Security group for SSH and HTTP access",
"SecurityGroupIngress": [
{
"IpProtocol":"tcp",
"FromPort":"80",
"ToPort":"80",
"CidrIp": "0.0.0.0/0"
},
{
"Fn::If": [
"AllowSSHAccess",
{
"IpProtocol":"tcp",
"FromPort":"22",
"ToPort":"22",
"CidrIp": { "Ref": "ParamAllowSSHFromRange" }
},
{
"Ref": "AWS::NoValue"
}
]
}
]
}
}
},
"Outputs": {
"SecurityGroupName": {
"Description": "Name of Instance Security Group",
"Value": {
"Ref": "SecurityGroup"
}
},
"SecurityGroupId": {
"Description": "ID of Instance Security Group",
"Value": {
"Fn::GetAtt": [
"SecurityGroup",
"GroupId"
]
},
"Export": {
"Name": {
"Fn::Sub": "${AWS::StackName}-SecurityGroupId"
}
}
}
}
}
Next Steps
The Next Post - Relaunch!
The Previous Post - Transforms
The Complete CloudFormation Guide Index
If you're enjoying this series and finding it useful, be sure to check out the rest of the blog posts in it! The links below will take you to the other posts in The Complete CloudFormation Guide here on Tech Guides and Thoughts so you can continue building your CloudFormation template along with me.
- The Complete CloudFormation Guide
- An Introduction to and History of CloudFormation
- The Main Concepts of CloudFormation
- How CloudFormation Does Updates and Deletes
- Our Project Setup
- Resources
- Parameters and Refs
- Our First Time Launch
- Functions, Pseudo Parameters, and Conditions Part 1
- Functions, Pseudo Parameters, and Conditions Part 2
- Mappings
- Transforms
- Outputs
- Relaunch!
- The Best Next Steps to Take from Here
Enjoy Posts Like These? Sign up to my mailing list!
J Cole Morrison
http://start.jcolemorrison.comDeveloper Advocate @HashiCorp, DevOps Enthusiast, Startup Lover, Teaching at awsdevops.io