Created
July 1, 2022 03:25
-
-
Save cromyhector/2f8e647f72068c96423d290a886497f0 to your computer and use it in GitHub Desktop.
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 json | |
import boto3 | |
ec2 = boto3.resource('ec2', region_name='us-east-1') | |
def lambda_handler(event, context): | |
instances = ec2.instances.filter(Filters=[ | |
{ | |
'Name': 'instance-state-name', | |
'Values': ['stopped'] | |
}, | |
{ | |
'Name': 'tag:Env', | |
'Values':['Dev'] | |
} | |
]) | |
for instance in instances: | |
id=instance.id | |
ec2.instances.filter(InstanceIds=[id]).start() | |
print("Instance ID is started :- "+instance.id) | |
return "success" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment