Created
November 9, 2022 02:56
-
-
Save sidward35/6b652c9b417a34b22d5b398ade77ba0d to your computer and use it in GitHub Desktop.
Scripts to start/stop EC2. Requires 'AmazonEC2FullAccess' permission.
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 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]) | |
} |
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 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