Understanding the use cases of the template macro
Before we dive into the internals of macros, we need to know what we can solve with them. Let's look at a few cases and examples.
Auto filling resource property values
Imagine having a launch template where you need to define an AMI ID. For Amazon Linux AMI, you could use AWS's parameter store:
Parameters: ImageId: Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id> Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' Resources: LaunchTemplate: Type: "AWS::EC2::LaunchTemplate" Properties: LaunchTemplateData: ImageId: !Ref ImageId
But what if we don't use Amazon Linux, but Ubuntu? We'd have to manually specify the AMI IDs and use mappings:
Mappings: ...