November 25, 2020 / Eternal Team
Intrinsic Functions in CloudFormation provide assistance in assigning values to template properties that aren’t available until runtime.
Let us take a simple example of FindMap:
1. FindMap using YAML
As we already know that using FindinMap we can determine which AMI to use for which region. So FindInMap is the intrinsic function that we’re going to use here in our example:
Mappings: RegionsMap: Us-east-1: HVM64: “ami-0dsfsf……” HVMG2: “ami-0a5fger…..” Eu-west-1: HVM64: “ami-45vdwd….” HVMG2: “ami-31c2fe...”
So in our example we have mappings header, and then we have the RegionMap, which is the name of our mapping, and under we list all of the regions, and then the HVM64 or the HVMG2 AMI ID Like
Resources: my EC2 instance: Type : “AWS::EC2::instance” properties : imageId : !FIndINMap -RegionMap -!Ref ‘AWS::Region’ -HVM64 InstanceType:m1.small
Now we can define resources, properties and imageID, but if you check it again in imageID you will see the exclamation mark FindInMap function call and we specify the call to the RegionMap mapping, and then we specify the Ref! and then region, and then we specify that we want the HVM64 result.
2. Find Map using JSON example
It’s similar to YAML, but you can see more brackets and colons. And this is how we run the function. There are some square brackets and then define that we’re looking for RegionMap, and then the Ref function on the AWS Region.
Now let’s look at “What is Nesting in CloudFormation?”.
So stack contains resources and resources is like s3 bucket, ec2 instance or many AWS services. With nesting, a whole other stack can be a resource.
So why would we do this?
Well, it allows a huge set of infrastructure to be split over multiple templates. As we know there are some limitations of CloudFormation stacks like in CloudFormation stacks we allow only 200 resources, 60 outputs, or 60 parameters.
We learned about CloudFormation’s different format in YAML/JSON and also saw what are nested stacks, why they are important and how are they implemented.