Skip to content

Instantly share code, notes, and snippets.

@mcj-la
Created September 22, 2020 15:34
Show Gist options
  • Save mcj-la/a51477a3886cdf6f615b076bf9246d07 to your computer and use it in GitHub Desktop.
Save mcj-la/a51477a3886cdf6f615b076bf9246d07 to your computer and use it in GitHub Desktop.
Lambda Function
import boto3
#This simple lambda function is available from AWS with instructions on starting and stopping an instance at regular intervals using Lambda and CloudWatch: https://aws.amazon.com/premiumsupport/knowledge-center/start-stop-lambda-cloudwatch/
# Enter the region your instances are in. Include only the region without specifying Availability Zone; e.g., 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX'] you can comma separate the instance IDs for more than one instance: i.e. ['X-XXXXXXXXX', 'X-XXXXXXXXX"]
instances = ['i-0902effe70a087ae7']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
@narasimhathejarao
Copy link

can we pull multiple instance id's from lambda environment variables ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment