Skip to content

Instantly share code, notes, and snippets.

@lbjay
Created February 1, 2016 16:28
Show Gist options
  • Save lbjay/766a716f3e42bb7270ff to your computer and use it in GitHub Desktop.
Save lbjay/766a716f3e42bb7270ff to your computer and use it in GitHub Desktop.
Get opsworks stack name from agent config
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