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.

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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠