J Cole Morrison
J Cole Morrison

J Cole Morrison

DevOps Specialist, Software Engineer, former Techstars Hackstar, and Founder / Instructor at AwsDevops.io!



Complete Guides:

CloudFormation Complete Guide

The Complete CloudFormation Guide: Parameters and Refs

Posted by J Cole Morrison on .

The Complete CloudFormation Guide: Parameters and Refs

Posted by J Cole Morrison on .

The Complete CloudFormation Guide Parameters Refs

Table of Contents

  1. Introduction
  2. What Are We Doing?
  3. The Video: Parameters & Refs
  4. The Template So Far
  5. Next Steps
  6. The Complete CloudFormation Guide Index

Introduction

So right now our template is reusable but not as much as it could be since we have some stuff hard-coded into it (like the author name and the SSH range). Since we would prefer that to not be the case, we're going to discuss the solutions available to us here with Parameters and Refs. Parameters are how we can pass our template custom settings on creation so that the stack we've created with it won't be limited to the things that are hard-coded into it. And Refs, aka references, are what allows us to use parameters throughout our template and they're also how we can have resources reference one another.

To see how these two properties work in practice, we'll be returning to our template with an eye on making it more reusable in the future. Something to keep in mind: Refs are special functions in CloudFormation, named intrinsic functions. Intrinsic functions are something we'll discuss multiple times in this series and they're all used in similar ways so we'll look into some other options available to us with them.

Now, parameters are one of those things that make a LOT more sense once you see them in action so be sure to experiment with them on your own to see how useful they can be. In the end, our security group and template are at a state where we can actually launch it, so that's what we'll be onto doing next!

What Are We Doing?

In this video, we'll be returning to our AWS CloudFormation template to set up a couple of Parameters which will make our template more flexible when being reused. We'll also discuss AWS-specific and SSM parameter types. Then, using the Parameters section in the console, we'll practice how to use refs to bind parts of our template to one another.

The Video: Parameters & Refs

The Template So Far

{
  "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"
    }
  },
  "Resources": {
    "SecurityGroup": {
      "Type": "AWS::EC2::SecurityGroup",
      "Properties": {
        "GroupName": "instance-sg",
        "GroupDescription": "Security group for SSH and HTTP access",
        "SecurityGroupIngress": [
          {
            "IpProtocol":"tcp",
            "FromPort":"80",
            "ToPort":"80",
            "CidrIp": "0.0.0.0/0"
          },
          {
            "IpProtocol":"tcp",
            "FromPort":"22",
            "ToPort":"22",
            "CidrIp": { "Ref": "ParamAllowSSHFromRange" }
          }
        ]
      }
    }
  }
}

Next Steps

The Next Post - Our First Time Launch

The Previous Post - Resources

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.

  1. The Complete CloudFormation Guide
  2. An Introduction to and History of CloudFormation
  3. The Main Concepts of CloudFormation
  4. How CloudFormation Does Updates and Deletes
  5. Our Project Setup
  6. Resources
  7. Parameters and Refs
  8. Our First Time Launch
  9. Functions, Pseudo Parameters, and Conditions Part 1
  10. Functions, Pseudo Parameters, and Conditions Part 2
  11. Mappings
  12. Transforms
  13. Outputs
  14. Relaunch!
  15. The Best Next Steps to Take from Here

Enjoy Posts Like These? Sign up to my mailing list!

My Tech Guides and Thoughts Mailing List

J Cole Morrison

J Cole Morrison

http://start.jcolemorrison.com

DevOps Specialist, Software Engineer, former Techstars Hackstar, and Founder / Instructor at AwsDevops.io!

View Comments...
J Cole Morrison

J Cole Morrison

DevOps Specialist, Software Engineer, former Techstars Hackstar, and Founder / Instructor at AwsDevops.io!



Complete Guides: