How To: Mappings In AWS CloudFormation Template (4 Min) | Match Key To Named Values

Опубликовано: 15 Март 2023
на канале: Gokce DB
26

In this tutorial, you'll learn how to use mappings in AWS CloudFormation templates. The optional Mappings section matches a key to a corresponding set of named values.
_
Video Transcript:
_
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to use the mapping section to map a key to a set of corresponding named values in AWs cloud template. Let's get into it. Let's start by navigating to cloud formation service then click on create a stack with new resources.

I'm going to upload a template file here called EC2-test dot EML. In this file, I'm starting by defining a mapping section with a mapping called region and environment type to AMI ID. This is a two-level map.

The first level is the region and the second level is the environment type. On line three, I'm defining the AMI IDs for US East 2 region in test and prod environments. Similarly, on line 6, I'm defining the AMI IDs for US East.

One region for test and prod environments. On line 10, I'm starting the parameter section and defining a parameter called environment type which is of the typed string and has a default value of test but the allowed values are test and prod. I also have specified a description that says to enter test or prod.

On line 19, I'm starting the resources section and I have a resource defined called web servicer instance which is of the type EC2. Under properties, to find the image ID, I'm using the find in map function with three parameters. For the first parameter, I'm specifying the map that we defined earlier called region and environment type to AMI ID. For the second parameter, I'm using the ref function to grab the value of the current AWS region.

Note AWS colon, colon region is a pseudo parameter reference which is predefined by AWS cloud formation, and for the third parameter I'm using the ref function again. But this time grab the value of environment type which we defined in the parameters section. Finally, for instance, type, I'm specifying T2 dot micro.

Let's go back to the cloud formation window and upload this file then hit next. Give your stack a name then pick an environment type in the parameters section. I'm going to choose test and then hit next.

For stack options, I'm going to leave everything to their default values and then hit next. Review your stack configuration then click on the submit button. Your stack status should now be created in progress.

Give it a few minutes and it should eventually change to create an underscore complete. Navigate to the resources tab then click on the physical ID. Activate your instance ID in the EC2 dashboard then scroll down in the detail section.

Verify that the AMI ID is listed. Here matches the AMI ID in our map for the current region and environment type. In this example, I'm in the U.S. East region and we specified the test environment.

So the AMI ID is 77 AF foreign. There you have it. If you have any questions, leave them in the comments section below.

Don't forget to like, subscribe, and turn on your notification bell. Until next time.


Смотрите видео How To: Mappings In AWS CloudFormation Template (4 Min) | Match Key To Named Values онлайн без регистрации, длительностью 04 минут 18 секунд в хорошем hd качестве. Это видео добавил пользователь Gokce DB 15 Март 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 26 раз и оно понравилось людям.