Skip to content

Instantly share code, notes, and snippets.

@sidward35
Created November 9, 2022 02:56
Show Gist options
  • Save sidward35/6b652c9b417a34b22d5b398ade77ba0d to your computer and use it in GitHub Desktop.
Save sidward35/6b652c9b417a34b22d5b398ade77ba0d to your computer and use it in GitHub Desktop.
Scripts to start/stop EC2. Requires 'AmazonEC2FullAccess' permission.
import json
import boto3
def lambda_handler(event, context):
instances = ['INSTANCE_ID']
ec2 = boto3.client('ec2', region_name='us-east-1')
ec2.start_instances(InstanceIds=instances)
return {
'statusCode': 200,
'body': json.dumps('Started instance ' + instances[0])
}
import json
import boto3
def lambda_handler(event, context):
instances = ['INSTANCE_ID']
ec2 = boto3.client('ec2', region_name='us-east-1')
ec2.stop_instances(InstanceIds=instances)
return {
'statusCode': 200,
'body': json.dumps('Stopped instance ' + instances[0])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment