Last active
March 8, 2021 14:02
-
-
Save bblanchon/88243641b9339c3639d9564bd1f0c4c6 to your computer and use it in GitHub Desktop.
AWS Lambda: start EC2 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 = 'eu-west-3' | |
ec2 = boto3.client('ec2', region_name=region) | |
def lambda_handler(event, context): | |
instances = event['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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"logs:CreateLogGroup", | |
"logs:CreateLogStream", | |
"logs:PutLogEvents" | |
], | |
"Resource": "arn:aws:logs:*:*:*" | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"ec2:Start*", | |
"ec2:Stop*" | |
], | |
"Resource": "*" | |
} | |
] | |
} |
Replace start_instances
with stop_instances
to stop the EC2 instances.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be called with the following params: