-
-
Save adboot/745ce49936672d4228488a50e045b593 to your computer and use it in GitHub Desktop.
AWS EC2 Start Stop Lambda
This file contains hidden or 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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "VisualEditor0", | |
"Effect": "Allow", | |
"Action": [ | |
"ec2:Start*", | |
"ec2:Stop*", | |
"ec2:DescribeInstanceStatus" | |
], | |
"Resource": "*" | |
}, | |
{ | |
"Sid": "VisualEditor1", | |
"Effect": "Allow", | |
"Action": [ | |
"logs:CreateLogStream", | |
"logs:CreateLogGroup", | |
"logs:PutLogEvents" | |
], | |
"Resource": "arn:aws:logs:*:*:*" | |
} | |
] | |
} |
This file contains hidden or 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
56 3 ? * MON-SAT * |
This file contains hidden or 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 | |
region = 'us-east-1' | |
instances = ['i-001e2d04e37ccde3b'] | |
ec2 = boto3.client('ec2', region_name=region) | |
def lambda_handler(event, context): | |
print('Starting instances') | |
ec2.start_instances(InstanceIds=instances) |
This file contains hidden or 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 | |
region = 'us-east-1' | |
instances = ['i-001e2d04e37ccde3b'] | |
ec2 = boto3.client('ec2', region_name=region) | |
def lambda_handler(event, context): | |
print('Stopping instances') | |
ec2.stop_instances(InstanceIds=instances) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment