0

I'm working on a python lambda function, to request spot ec2 instances. I want to pass a script in UserData, such that i can do some file processing , say for the sake of this example copy files from one s3 to another, once done, would like to terminate the ec2 instance created. can someone provide sample script , maybe in python to achieve this.


def lambda_handler(event, context):
    ec2.request_spot_instances(
        SpotPrice='<-- max price for spot instance -->',
        InstanceCount=5,
        Type='one-time',
        LaunchSpecification={
            'ImageId': '<--- ami id ---> ',
            'InstanceType': '<-- instance type -->',
            'UserData': '',
            ...
        }
 )
arve
  • 569
  • 2
  • 10
  • 27
  • 2
    Just have the EC2 instances run something like `sudo shutdown -h now` to self-terminate after they are done with their tasks. – Mark B Sep 25 '20 at 20:43
  • Does this answer your question? [Self-Terminating AWS EC2 Instance?](https://stackoverflow.com/questions/10541363/self-terminating-aws-ec2-instance) – JD D Sep 26 '20 at 00:26
  • Also: [Auto-Stop EC2 instances when they finish a task - DEV Community](https://dev.to/aws/auto-stop-ec2-instances-when-they-finish-a-task-2f0i) – John Rotenstein Sep 26 '20 at 04:45

0 Answers0