amazon web services - Create AMI when EC2 instance shuts down -
i need create ami when instance terminated/shuts down up. setup cloudwatch rule on ec2 instance state changed event create ami via ssm run command (target document aws-runshellscript(linux)). works fine, if provide hardcoded instance id command parameter.
/home/ec2-user/createimage.sh i-123456
this rule needs applied instances. need instance-id dynamically source , send target. tried input transformer not getting data source. dynamic parameters {{variable name}} not working. suggestions.
thanks.
you can configure amazon cloudwatch events rule:
you can have rule trigger aws lambda function triggers snapshot. when lambda function triggered, following information passed function:
{ "version": "0", "id": "01345791-08ce-baaf-78f5-437aca50f13c", "detail-type": "ec2 instance state-change notification", "source": "aws.ec2", "account": "123456789012", "time": "2017-09-12t00:28:55z", "region": "ap-southeast-2", "resources": [ "arn:aws:ec2:ap-southeast-2:123456789012:instance/i-0cf605453b22f703e" ], "detail": { "instance-id": "i-0cf605453b22f703e", "state": "stopped" } }
note instance id passed message, can use in createsnapshot
command within lambda function.
Comments
Post a Comment