I am compiling a fairly complex CloudFormation template and at some point I am creating an ec2 instance;
I want to create a lambda function that:
Is this possible?
Ι am asking because (among others) ec2 is not listed as a potential lambda trigger in the console and wanted to see whether there is a simpler way around this than posting details about the creation in an sns or sqs which then in turn triggers the lambda.
There are two options that I can think of:
As user @krishna_mee2004 stated, you can use CloudWatch to listen on your EC2 instance and this in turn will trigger your lambda.
On your EC2 instance, there is a field called User data under the Instance Details. In User data you can add commands that should be ran whenever your EC2 instance is deployed. From here you can invoke your lambda.
Here is documentation on EC2 user data. Here is documentation on invoking your lambda from the CLI.
Personally, I'd recommend option 1 because I prefer using AWS tools whenever I get the chance and CloudWatch is a perfect example of this. However, option 2 might give you more control over what payload is sent to the lambda.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With