Created
March 23, 2021 18:14
-
-
Save asolera/de095aa7d5c6073f3dec27ca1af45e7f to your computer and use it in GitHub Desktop.
Stop AWS EC2 Instances with Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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