Adventures in AWS: Error launching CloudFormation stacks in Powershell

This blog post definitely falls under the “Note to Self” category, because I’ve run into this issue like three times now, so here’s hoping that writing down the answer helps me (and maybe you too).

If you launch CloudFormation stacks through the AWS Powershell Tools with the New-CFNStack cmdlet, you may have run into this funky error from time to time:

 New-CFNStack: Object reference not set to an instance of an object.

This is not a helpful error message, and I’ve seen it mean a couple different things.

Reason 1 (most common): You’re missing a required template parameter

The New-CFNStack cmdlet takes an array of Amazon.CloudFormation.Model.Parameter key-value pairs as an argument to the “Parameters” parameter. If you try to put a null value in one of those parameter objects and your CloudFormation template doesn’t allow that parameter to be null, you’ll get the error specified above. This can be hard to debug because normally you’d expect a Powershell cmdlet to come back with an error message like “No argument was specified for parameter ‘X'” in such situation. Again, like I said, bad error message, but an easy fix.

Reason 2 (incredibly specific and stupid): You’re using an old version of the Powershell Tools with named credential profiles

Hopefully nobody else has run into this one. Recent versions of the Powershell Tools include a common parameter called “ProfileName”, which can be used to specify the name of an AWS access keypair saved in your .aws/credentials file or the SDK Store. The old “StoredCredentials” common parameter is still available for backwards compatibility. If you’re using a version of the Powershell Tools older than 2.1.9 (I think), the StoredCredentials parameter is all you get, but it doesn’t work too well with profiles saved in .aws/credentials instead of the SDK Store. In fact, I’ve gotten the “object reference” New-CFNStack error when trying to use named profiles with that cmdlet. Moral of the story: keep your AWS Tools up to date and you’ll never see this issue.

I’ll update this post if I find any other issues with this cmdlet. Thanks for reading!

Adventures in AWS: Error launching CloudFormation stacks in Powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s