Last active
October 16, 2016 19:12
-
-
Save kepstein/073c4b9cb6af28e57127a54a034bcf83 to your computer and use it in GitHub Desktop.
Tag an AWS EC2 instance on instantiation or reboot
This file contains 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
#!/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