Skip to content

Instantly share code, notes, and snippets.

@cromyhector
Created July 1, 2022 04:31
Show Gist options
  • Save cromyhector/f860380899aa7a56dd38d53fd0fe3587 to your computer and use it in GitHub Desktop.
Save cromyhector/f860380899aa7a56dd38d53fd0fe3587 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': ['running']
},
{
'Name': 'tag:Env',
'Values':['Dev']
}
])
for instance in instances:
id=instance.id
ec2.instances.filter(InstanceIds=[id]).stop()
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