Skip to content

Instantly share code, notes, and snippets.

@100daysofdevops
Created February 23, 2019 18:50
Show Gist options
  • Select an option

  • Save 100daysofdevops/82b7db36251ca4dbcc2c5bfcc6105639 to your computer and use it in GitHub Desktop.

Select an option

Save 100daysofdevops/82b7db36251ca4dbcc2c5bfcc6105639 to your computer and use it in GitHub Desktop.
import boto3
# Enter the region your instances are in. Include only the region without specifying Availability Zone; e.g., 'us-east-1'
region = 'XX-XXXXX-X'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['X-XXXXXXXX']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
print 'stopped your instances: ' + str(instances)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment