Skip to content

Instantly share code, notes, and snippets.

@zgolus
Created June 2, 2016 21:36
Show Gist options
  • Save zgolus/d3e94a32e20c99f50dd259726f56c118 to your computer and use it in GitHub Desktop.
Save zgolus/d3e94a32e20c99f50dd259726f56c118 to your computer and use it in GitHub Desktop.
import boto3
import pprint
def lambda_handler(event, context):
ec2 = boto3.client('ec2')
resp = ec2.describe_instances(
Filters=[
{
'Name': 'instance-state-name',
'Values': [
'running'
]
}
]
)
for reservation in resp['Reservations']:
pprint.pprint('stopping ' + reservation['Instances'][0]['InstanceId'])
ec2.stop_instances(InstanceIds=[reservation['Instances'][0]['InstanceId']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment