Created
August 11, 2020 20:24
-
-
Save nktstudios/5150810740be1b8a6f3a31408dc42d42 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
Thanks NKT Studios. for sharing!