|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import boto3 |
| 3 | +import argparse |
| 4 | +from os import path |
| 5 | + |
| 6 | +parser = argparse.ArgumentParser() |
| 7 | +parser.add_argument('-n', '--stack-name', type=str, required=True, help="Name of PCUI stack") |
| 8 | +parser.add_argument('-r', '--region', type=str, required=False, help="Region of PCUI stack if different from AWS_DEFAULT_REGION") |
| 9 | +args = parser.parse_args() |
| 10 | + |
| 11 | +client = boto3.client('cloudformation', region_name=args.region) |
| 12 | + |
| 13 | +def get_nested_stack_name(logical_id, stack_name=args.stack_name): |
| 14 | + nested_stack = client.describe_stack_resource(StackName=stack_name, LogicalResourceId=logical_id) |
| 15 | + return nested_stack['StackResourceDetail']['PhysicalResourceId'] |
| 16 | + |
| 17 | +def get_output(stack_name, output_key): |
| 18 | + stack = client.describe_stacks(StackName=stack_name)['Stacks'][0] |
| 19 | + return next((o.get("OutputValue") for o in stack.get('Outputs', []) if o.get("OutputKey") == output_key), None) |
| 20 | + |
| 21 | +pc_api_stack_name = get_nested_stack_name('ParallelClusterApi') |
| 22 | +pcui_cognito_stack_name = get_nested_stack_name('Cognito') |
| 23 | +outpath = f"{path.dirname(path.dirname(__file__))}/.env" |
| 24 | + |
| 25 | +with open(outpath, 'w') as file: |
| 26 | + file.write(f"export API_BASE_URL={get_output(pc_api_stack_name, 'ParallelClusterApiInvokeUrl')}\n") |
| 27 | + file.write("export ENV=dev\n") |
| 28 | + file.write(f"export SECRET_ID={get_output(args.stack_name, 'UserPoolClientSecretName')}\n") |
| 29 | + file.write("export SITE_URL=http://localhost:5001\n") |
| 30 | + file.write(f"export AUDIENCE={get_output(args.stack_name, 'AppClientId')}\n") |
| 31 | + file.write(f"export AUTH_PATH={get_output(pcui_cognito_stack_name, 'UserPoolAuthDomain')}") |
| 32 | + |
| 33 | +print(f"Wrote to {outpath}") |
0 commit comments