AWS CloudFormation Tips
If you have been developing on AWS, then you are probably already come across CloudFormation. There is a lot to CloudFormation, so even if you have been using it for a while, there are bound to be things still to learn.
In this post, I’m going to go over a few interesting things that you might not yet know and hope that this helps you in your CloudFormation journey.
Linting
If you want to increase your productivity while working with CloudFormation, then it’s important to reduce the amount of time you spend writing and deploying templates. This means we need a way to eliminate any errors. There’s nothing worse than waiting for a stack to deploy, only to find out there are errors in your template.
A great solution here is to use cfn-lint to make sure you don’t start the deploy if there are errors in your template.
Parameter Validation
When deploying using CloudFormation, you can make it easier to put in the right parameters by using AllowedPattern and AllowedValues.
Both of these only consider one parameter at a time. There is a way to validate Parameters that have a relationship with other parameters, though. Because you might want to validate that two parameters are mutually exclusive or that if one parameter is set, another parameter also has to have a value.
This is probably the most hidden CloudFormation feature because it’s documented in the Service Catalog documentation. And even though the Rules section seems to be a Service Catalog feature, you can use it directly in CloudFormation too.
Resource Providers
Resource Providers work similar to Custom Resources, and you will not see a big difference in your templates although they are easier to manage.
When you write your own Resource Provider, you also implement and expose a Read and List handler. This new approach gives you almost the same capabilities as a native CloudFormation resource.
By creating resource providers, modern features like drift detection and resource import work with your own resources – and will work with every new resource that AWS releases support for.
There is also an integration with AWS Config for your Resource Providers, and AWS is developing more and more resource providers in the open.