Created
February 3, 2022 06:54
-
-
Save MOAMIndustries/53e2eb0cc1e564975cf215cb88b92314 to your computer and use it in GitHub Desktop.
Generates a .env file with all of the logical resources ids mapped to the Physical resource ID to help facilitate tests
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
import boto3 | |
import toml | |
#read samconfig.toml | |
#find the stack name | |
#describe stack | |
# output resourceIDs as env file | |
env_path = './.env' | |
config = toml.load('../samconfig.toml') | |
stack_name= config['default']['deploy']['parameters']['stack_name'] | |
region= config['default']['deploy']['parameters']['region'] | |
aws_profile = config['default']['deploy']['parameters']['profile'] | |
session = boto3.Session(profile_name=aws_profile) | |
cf_client = session.client('cloudformation') | |
desc_stack_response = cf_client.describe_stacks(StackName=stack_name) | |
stack_resoure_response = cf_client.list_stack_resources(StackName=stack_name) | |
resources_list = stack_resoure_response['StackResourceSummaries'] | |
with open(env_path,'w') as env: | |
env.write(f"profile={aws_profile}\n") | |
env.write(f"region={region}\n") | |
for resource in resources_list: | |
env.write(f"{resource['LogicalResourceId']}={resource['PhysicalResourceId']}\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment