Skip to main content

CloudFormation Templates: Using Ref to Access Run Time Information

When working with AWS CloudFormation, many of the resource properties we reference in our stack template will not be available until the stack is built and creation of that particular resource has been initiated.

For example, suppose we're declaring an ECS service called MigrateDatabaseService to run and maintain a task based on the MigrateTask task definition. One of the required properties of the AWS::ECS::Service resource is a string containing the Amazon Resource Name (ARN) of the task definition (including the revision number) that we want to run on the cluster. The problem is that the task definition is declared in the same template, but the ARN will not be available until run time. So, how do we specify a run time value at design time?


CloudFormation provides eleven built-in, or intrinsic, functions that we can use to assign values to properties that are not available until run time.

The intrinsic function we need to use to populate the TaskDefinition property in the service resource declaration is the Ref function. Given the logical name of another resource declared in the template, Ref returns the value of the specified resource.

The AWSdocumentation provides an extensive list of the reference values returned by the Ref function for many different resource types, along with example return values. We can see that, for a TaskDefinition resource, Ref returns the task definition ARN, which is exactly what we need to declare the TaskDefinition property in the template:



Note that CloudFormation templates are required to be valid JSON, which means the TaskDefinition property requires a single value. So, while the call to Ref returns a single value, CloudFormation will see the call itself (“Ref”: “MigrateTask”) as another key/value pair, and will generate a template format error (“Expected ‘,’ instead of ‘:’”). Make the call to Ref  by enclosing it in curly brackets so that CloudFormation sees it as a single object, not a key/value pair.


Comments

Popular posts from this blog

Takeaways from the Continuous Automated Testing Tutorial at CAST2014

I had the opportunity to attend Noah Sussman's tutorial on Continuous Automated Testing last week as part of CAST2014. It was a great tutorial, with most of the morning spent on the theory and concepts behind continuous automated testing, and the afternoon spent with some hands-on exercises. I think that Noah really understands the problems associated with test automation in an agile environment, and the solutions that he presented in his tutorial show the true depth of his understanding of, and insight into, those problems. Here are some of the main highlights and takeaways that I got from his tutorial at CAST2014. Key Concepts Design Tools – QA and testing are design tools, and the purpose of software testing is to design systems that are deterministic Efficiency-to-Thoroughness-Trade-Offs – (ETTO) We do not always pick the best option, we pick the one that best meets the immediate needs Ironies of automation – Automation makes things more complex and, while tools can make...

Let’s Continue to Drive Software Testing Education Forward

It’s Time to Embrace the Student Who Learns Differently Last in a series. In my last two posts I’ve written about enhancing the student and instructor experience in the AST’s BBST courses by focusing on updating the Fieldstones and making BBST courses more accessible by identifying some of the more common obstacles to BBST participation, and then working collectively to find ways to lower or remove those obstacles. In this post, I want to discuss the third and final area I would like to concentrate on if elected to the Board of Directors: researching and establishing alternate approaches to teaching that better suit different learning styles. As members of the AST, we have access to some of the best information and training available in the field of software testing. The AST hosts the Conference of the Association for Software Testing (CAST) each year, providing full-day tutorials, keynotes, and track sessions. They also offer four separate BBST courses:  Foundations, ...

Book Review - The Shape of Actions: What Humans and Machines Can Do

If you’re a tester and you’ve been around social media, attended a conference, watched a webinar, read blog posts, or watched videos of other testers speaking on YouTube, you may have heard at least one mention of polimorphic and/or mimeomorphic actions. But what does it mean when someone says that an action is polimorphic or mimeomorphic? Where do these ideas come from, and why, as testers, do we care? The concepts of polimorphic and mimeomorphic actions come from the book The Shape of Actions: What Humans and Machines Can Do, by Harry Collins and Martin Kusch. In the book the authors develop a new theory about what they call the shape of actions. I’ve attempted to cover the highlights and general topics of discussion, or at least what I found most interesting, from each chapter in the summary below. Chapter 1 – Humans and Machines In Chapter 1, Collins and Kusch introduce the reader to their theory which basically states that humans can do three things – they can do polimorp...