Package: cfn-ami-to-mapping
Get AMI IDs per region automatically for your CloudFormation templateIn most cases, people use the Mapping section in CloudFormation to associate AMI IDs with AWS regions as described inTHISexample.I know how is it annoying to manually searching for AMI IDs in different AWS regions and build that map on your own, especially if your map is bigger than one image per region. That's why this tool had been created.How to installInstall viapipAh, that's easy, just run next commandpip install cfn-ami-to-mappingOr you can build source codeClone the repositorygit clone https://github.com/99stealth/cfn-ami-to-mapping.gitRun the commandmake installHow to useLong story shortI also know how it's annoying to read all this stuff. So, enjoy watching :eyes:Single imageThe scenarioThere is a requirement for only one image per region.Ok, all you need to specify it's AMI id and an AWS region where it locates.cfn-ami-to-mapping --image-name ami-02f706d959cedf892 --top-level-key AMIID --region us-east-2or instead of AMI id, you may specify the image namecfn-ami-to-mapping --image-name amzn-ami-hvm-2018.03.0.20190611-x86_64-gp2 --top-level-key AMIID --region us-east-2Wait several seconds and you will get your autogenerated block of mappingAMIRegionMap:ap-northeast-1:AMILinux:ami-04b2d1589ab1d972cap-northeast-2:AMILinux:ami-0be3e6f84d3b968cdap-south-1:AMILinux:ami-0b99c7725b9484f9eap-southeast-1:AMILinux:ami-0fb6b6f9e81056553ap-southeast-2:AMILinux:ami-075caa3491def750bca-central-1:AMILinux:ami-0a67d15f2858e33cbeu-central-1:AMILinux:ami-026d3b3672c6e7b66eu-north-1:AMILinux:ami-8c169ef2eu-west-1:AMILinux:ami-0862aabda3fb488b5eu-west-2:AMILinux:ami-0bdfa1adc3878cd23eu-west-3:AMILinux:ami-05b93cd5a1b552734sa-east-1:AMILinux:ami-0bb96001cf2299257us-east-1:AMILinux:ami-035b3c7efe6d061d5us-east-2:AMILinux:ami-02f706d959cedf892us-west-1:AMILinux:ami-0fcdcdb074d2bac5fus-west-2:AMILinux:ami-0f2176987ee50226eSeveral imagesOk, but there are cases when you should specify several images andFn::FindInMapthem based on some inputParameteror maybe something else.The scenarioYou need to have possibility to swap your infrastructure fromAmazon LinuxtoAmazon Linux 2.Ok, then try to specify several values:cfn-ami-to-mapping -i ami-035b3c7efe6d061d5 -k AMILinux -i ami-0b898040803850657 -k AMILinux2 --jsonHere's what you'll get:AMIRegionMap:ap-northeast-1:AMILinux:ami-04b2d1589ab1d972cAMILinux2:ami-0c3fd0f5d33134a76ap-northeast-2:AMILinux:ami-0be3e6f84d3b968cdAMILinux2:ami-095ca789e0549777dap-south-1:AMILinux:ami-0b99c7725b9484f9eAMILinux2:ami-0d2692b6acea72ee6ap-southeast-1:AMILinux:ami-0fb6b6f9e81056553AMILinux2:ami-01f7527546b557442ap-southeast-2:AMILinux:ami-075caa3491def750bAMILinux2:ami-0dc96254d5535925fca-central-1:AMILinux:ami-0a67d15f2858e33cbAMILinux2:ami-0d4ae09ec9361d8aceu-central-1:AMILinux:ami-026d3b3672c6e7b66AMILinux2:ami-0cc293023f983ed53eu-north-1:AMILinux:ami-8c169ef2AMILinux2:ami-3f36be41eu-west-1:AMILinux:ami-0862aabda3fb488b5AMILinux2:ami-0bbc25e23a7640b9beu-west-2:AMILinux:ami-0bdfa1adc3878cd23AMILinux2:ami-0d8e27447ec2c8410eu-west-3:AMILinux:ami-05b93cd5a1b552734AMILinux2:ami-0adcddd3324248c4csa-east-1:AMILinux:ami-0bb96001cf2299257AMILinux2:ami-058943e7d9b9cabfbus-east-1:AMILinux:ami-035b3c7efe6d061d5AMILinux2:ami-0b898040803850657us-east-2:AMILinux:ami-02f706d959cedf892AMILinux2:ami-0d8f6eb4f641ef691us-west-1:AMILinux:ami-0fcdcdb074d2bac5fAMILinux2:ami-056ee704806822732us-west-2:AMILinux:ami-0f2176987ee50226eAMILinux2:ami-082b5a644766e0e6f:warning: Please, pay attentionYou may not specify a region, in this case, it will use default one which isus-east-1. Therefore you need to specify AMI ID of image fromus-east-1.By default utility creates output usingyamlformat. If you want to change it tojson, then run the utility with--jsonflag.cfn-ami-to-mapping --image-id ami-02f706d959cedf892 --top-level-key AMIID --us-east-2 --jsonAnd the output:{"AMIRegionMap":{"ap-northeast-1":{"AMILinux":"ami-04b2d1589ab1d972c"},"ap-northeast-2":{"AMILinux":"ami-0be3e6f84d3b968cd"},"ap-south-1":{"AMILinux":"ami-0b99c7725b9484f9e"},"ap-southeast-1":{"AMILinux":"ami-0fb6b6f9e81056553"},"ap-southeast-2":{"AMILinux":"ami-075caa3491def750b"},"ca-central-1":{"AMILinux":"ami-0a67d15f2858e33cb"},"eu-central-1":{"AMILinux":"ami-026d3b3672c6e7b66"},"eu-north-1":{"AMILinux":"ami-8c169ef2"},"eu-west-1":{"AMILinux":"ami-0862aabda3fb488b5"},"eu-west-2":{"AMILinux":"ami-0bdfa1adc3878cd23"},"eu-west-3":{"AMILinux":"ami-05b93cd5a1b552734"},"sa-east-1":{"AMILinux":"ami-0bb96001cf2299257"},"us-east-1":{"AMILinux":"ami-035b3c7efe6d061d5"},"us-east-2":{"AMILinux":"ami-02f706d959cedf892"},"us-west-1":{"AMILinux":"ami-0fcdcdb074d2bac5f"},"us-west-2":{"AMILinux":"ami-0f2176987ee50226e"}}}:warning: It doesn't work perfectly, so please reportIssuesif you faced with any problem during the installation.