-
-
Save cvargas-xbrein/1ff6b67bb690290833d80789bb507854 to your computer and use it in GitHub Desktop.
Start Stop EC2
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 | |
region = 'us-east-2' | |
ec2 = boto3.client('ec2', region_name=region) | |
def lambda_handler(event, context): | |
instances = event["instances"].split(',') | |
action = event["action"] | |
if action == 'Start': | |
print("STARTing your instances: " + str(instances)) | |
ec2.start_instances(InstanceIds=instances) | |
response = "Successfully started instances: " + str(instances) | |
elif action == 'Stop': | |
print("STOPping your instances: " + str(instances)) | |
ec2.stop_instances(InstanceIds=instances) | |
response = "Successfully stopped instances: " + str(instances) | |
return { | |
'statusCode': 200, | |
'body': json.dumps(response) | |
} |
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
{ | |
"instances": "PUT YOUR INSTANCE ID's HERE", | |
"action": "Start" | |
} |
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
{ | |
"instances": "PUT YOUR INSTANCE ID's HERE", | |
"action": "Stop" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment