Skip to content

Instantly share code, notes, and snippets.

@kepstein
Last active October 16, 2016 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kepstein/073c4b9cb6af28e57127a54a034bcf83 to your computer and use it in GitHub Desktop.
Save kepstein/073c4b9cb6af28e57127a54a034bcf83 to your computer and use it in GitHub Desktop.
Tag an AWS EC2 instance on instantiation or reboot
#!/usr/bin/python
# Use CloudWatch Events Trigger - Schedule:InstancePending
import boto3
import time
def main(event, context):
my_instance = str(event['detail']['instance-id'])
ec2 = boto3.client("ec2", region_name=str(event['region']))
ec2.create_tags(Resources=[my_instance], Tags=[{"Key": "Schedule", "Value": "days=All|stop=1800"}])
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment