Created
February 1, 2016 16:28
-
-
Save lbjay/766a716f3e42bb7270ff to your computer and use it in GitHub Desktop.
Get opsworks stack name from agent config
This file contains hidden or 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
| import os | |
| import boto3 | |
| from yaml import load | |
| os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1') | |
| if __name__ == '__main__': | |
| with open('/etc/aws/opsworks/instance-agent.yml') as f: | |
| agent_config = load(f) | |
| instance_id = agent_config[':identity'] | |
| opsworks = boto3.client('opsworks') | |
| instances = opsworks.describe_instances(InstanceIds=[instance_id]) | |
| stack_id = instances['Instances'][0]['StackId'] | |
| stacks = opsworks.describe_stacks(StackIds=[stack_id]) | |
| print stacks['Stacks'][0]['Name'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment