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.

已提問 6 個月前檢視次數 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
已回答 6 個月前
profile pictureAWS
專家
已審閱 6 個月前
profile picture
專家
已審閱 6 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南