CloudFormation with a code hook maybe using Lambda

0

I know this could be done in Terraform, Ansible and some other things like that. But this question is strictly for CloudFormation.

What I have is a CF Template that our Engineers run to create instances. And while they are supposed to manually pick which AZ to put the instance in often times they do not and the Template takes its default. What I want to know is if there is a way with maybe Lambda or something else in AWS that could do the calculations to see which AZ has the least number of instances in it then tell the CF Template to put the new instance and all its resources in that AZ without human intervention?

The second part of this question is if there is a way to do what I asked how complicated is it compared to doing it in Ansible or Terraform. Both of which would run on an instance inside of AWS with the proper roles to do script calculations and then deployment.

已提问 5 个月前190 查看次数
1 回答
1
已接受的回答

Hi,

What you want to do can be achieved with a Custom Resource. This is a type of resource in Cloudformation that excutes (and waits for a response from) a Lambda function.

The way it would work in your scenario would be to remove the option of the AZ from the parameters sections completely. Create a Lambda that does the lookup logic you describe and return the AZ. Then trigger this Lambda from a Custom Resource, this custom resource would then have a !Refor !GetAtt value that you can access to populate the AZ value for the instance in place of using a parmeter.

I hope this helps.

If you are likely to create your Lambda in Python then there is a helper library specifically designed to make Custom Resources simpler to create in Python.

profile pictureAWS
danjhd
已回答 5 个月前
profile pictureAWS
专家
已审核 5 个月前
profile picture
专家
已审核 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容