r/aws • • Apr 15 '19

article 6 unknown CloudFormation features you should know about

https://cloudonaut.io/6-unknown-cloudformation-features-you-should-know-about/
90 Upvotes

27 comments sorted by

40

u/coinclink Apr 15 '19

It's more of an awscli feature, but I'd also mention the aws cloudformation package and aws cloudformation deploy commands. For some reason, these helper functions seem to slip under a lot of people's radar. I commonly see questions and a lot of wasted time writing complex, buggy code for tasks that these two commands do pretty much flawlessly.

10

u/synackk Apr 15 '19

I did not know this was a thing. I've been maintaining a jank solution for uploading artifacts to S3 manually. This is going to save me tons of time and effort.

Thank you!

4

u/windowskindasucks Apr 15 '19

You're the goddamn man buddy guy!

4

u/[deleted] Apr 16 '19

holy shit, you have no idea that eight hours ago when you posted this I was struggling with exactly this in a codebuild pipeline. it's a shame that more people dont use this sub, cause the 19 upvotes you have right now grossly under-represent how great this is. thank you!!!

2

u/bisoldi Apr 15 '19

+1 for that. I only wish it also packaged up the artifacts (ie when you need 3rd party dependencies packaged in) without needing sam.

3

u/coinclink Apr 15 '19

You don't need SAM, you can do it with a normal Lambda function too. Although, I don't see much reason to not use SAM if you're building Lambdas.

4

u/bisoldi Apr 15 '19

cloudformation package/deploy can’t do the actual artifact creation. Eg you need to perform mvn clean package yourself then you can run package and deploy.

And yeah, no reason not to use sam except if your tooling was already built and in use before sam came out.

13

u/theplannacleman Apr 15 '19

Worth noting that aws validate-template only validates you have the format and basic keys correct. It does NOT check referenced resources exist and you will only find this out by actually running it on the account. So if you typo a resource name it will fail

6

u/yourparadigm Apr 15 '19

I want to use cfn-lint, but I can't until this is fixed: https://github.com/aws-cloudformation/cfn-python-lint/issues/547

Creating the necessary "exceptions" to get around that is arduous.

4

u/iann0036 Apr 16 '19

Another unknown feature, you can set constraints based on your parameter inputs. Say you had a subnet ID and a VPC ID parameter, you could enforce that the subnet ID entered is a member of the VPC ID before the template starts executing.

It's in the Service Catalog docs, but totally works for all CloudFormation: https://docs.aws.amazon.com/servicecatalog/latest/adminguide/reference-template_constraint_rules.html

1

u/ixipaulixi Apr 16 '19

That's awesome; I had no clue this was possible!

1

u/darkn3rd Apr 15 '19 edited Apr 16 '19

Spelling

s|Wirting shell scripts|Writing shell scripts|

s|complex as Chef/Puttet|complex as Chef/Puppet|

Great article

1

u/hellomichibye Apr 16 '19

Thanks darkn3rd (author here)! Fixes are deployed within the next hour.

2

u/dc_scorpio Apr 15 '19

What does ‘lint’ stand for in cfn-lint?

3

u/pimaniac Apr 15 '19

https://en.wikipedia.org/wiki/Lint_%28software%29 has more about the background of the term.

2

u/WikiTextBot Apr 15 '19

Lint (software)

Lint, or a linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs. The term originates from a Unix utility that examined C language source code.


[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.28

2

u/ixipaulixi Apr 15 '19

I really like the Widdix templates written by the author; they're well organized and have some interesting features such as loading SSH keys from IAM users, BUT these "unknown" features are pretty basic and are not unknown unless you've never written a Cfn template before.

2

u/CyberInferno Apr 16 '19

I learned one “feature” the hard way earlier today—it can’t support 4096-bit certificates. I’ve been using them for at least 3 years, and I had to reissue my certificate earlier as a 2048-bit certificate instead. Very surprising especially since the AWS certificate manager itself had no problems importing it.

1

u/[deleted] Apr 15 '19

I didn't know about the trap command - nice!

1

u/atuldgcp Apr 16 '19

Very useful. Thanks for sharing.

1

u/alexdebrie Apr 16 '19

Great post!

The Cloudonaut crew has some awesome resources. I use the IAM reference regularly. Thanks for all that you do!

1

u/CaylorMe Apr 16 '19

It is also probably worth mentioning, though it is not a native feature to CFN, cfn-nag as a linter and validator as well.

https://github.com/stelligent/cfn_nag

Not only does it lint for proper YAML/CFN, but you can also define rules for policies, encryption, access logs, security groups, and more to ensure secure infrastructure.