Skip to content

Instantly share code, notes, and snippets.

@cromyhector
Created July 1, 2022 03:25
Show Gist options
  • Save cromyhector/2f8e647f72068c96423d290a886497f0 to your computer and use it in GitHub Desktop.
Save cromyhector/2f8e647f72068c96423d290a886497f0 to your computer and use it in GitHub Desktop.
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