I am a Sr. DevOps Consultant in the Amazon Web Services Professional Services division. This article is my work using publicly available information and does not necessarily reflect the opinions of my employer.
Listen to the podcast! Spotify
Developers on the AWS platform often complain about AWS CloudFormation missing capabilities of imperative programming languages. This is true as CloudFormation uses a declarative programming model where you describe what you want, and CloudFormation does the work to create it.
If you want to have total control over your CloudFormation templates using an imperative programming language, you can use the Cloud Development Kit. Alternatively, CloudFormation can be extended through the use of macros. In a previous article, I discussed using the CloudFormation Include macro to incorporate one CloudFormation template inside another. This mimics the import, require commands found in other languages.
As with any application where input is accepted from the user, we may want to manipulate the provided input. As all CloudFormation parameters are strings, this article discusses using the string transformation macros available in GitHub.
The String Functions Macros
The String macros are useful for manipulating parameters and dynamic text created using the
!Join intrinsic functions. In my templates, I prefer to use a consistent case for text like tags, ensuring they can be easily found later and reduce the chance of confusion over case. The String macros provide the following string transformations:
- upper, converting the input text to all uppercase;
- lower, converting the input text to all lowercase;
- capitalize, making the first character a capital letter and the rest lower case;
- title, where the first character of every word is upper case;
- swap case, where the case of each letter is swapped, such as upper to lower; and,
- strip, which removes characters from the beginning or end of the string.