简体   繁体   中英

AWS Lambda spin up EC2 and triggers user data script

I need to spin up an instance using Lambda on S3 trigger. Lambda has to spin up an EC2 and trigger a user data script.

I have an aws cli something like aws —region use-east-1 s3 cp s3://mybucket/test.txt /file/

Looking for python boto3 implementation.Since lambda is new to me, can someone share if its doable?

One way is Lambda runs CFT and UserData is part of CFT, but think there should be an easier way to achieve this.

Just include UserData parameter in your Boto3 function.

You should use a code like that:

ec2.create_instances(
   ImageId='<ami-image-id>',
   InstanceType='t1.micro',
   UserData='string',
   ....

If you don't need to create, but just run, you should use:

 ec2.client.run_instances(
    ...
    UserData='string',
    ...

You can see all arguments that create_instance and run_instances support in:

http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Subnet.create_instances

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM