Skip to content

Triggering a lambda when a new ami is available

0

Im using packer to build new AMIs, is there a mechanism or a API call from aws to trigger a lambda whenever new AMI is created

or is there any other ways

1 Answer
2
Accepted Answer

Hello.

I think it's possible to get an event with EventBridge when the AMI creation is complete, so you can use that event to run Lambda.
If you set Lambda as the target of EventBridge, Lambda will be executed.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitor-ami-events.html

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

  • For exiting AMI its fine, But when new AMI is being create How to automate this , cause we dont know the arn before hand

  • The AMI ARN is included in the event.

    {
        "version": "0",
        "id": "example-9f07-51db-246b-d8b8441bcdf0",
        "detail-type": "EC2 AMI State Change",
        "source": "aws.ec2",
        "account": "012345678901",
        "time": "yyyy-mm-ddThh:mm:ssZ",
        "region": "us-east-1",
        "resources": ["arn:aws:ec2:us-east-1::image/ami-0123456789example"],
        "detail": {
            "RequestId": "example-9dcc-40a6-aa77-7ce457d5442b",
            "ImageId": "ami-0123456789example",
            "State": "available",
            "ErrorMessage": ""
        }
    }
    

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.