Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stop AWS EC2 Instances with Lambda
import boto3
import time
# Enter the region your instances are in, e.g. 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['i-03c24cxbd9x10ex51']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
return 'Stopping instances...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment