-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add boto3 script to fetch environment variables for development
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ infrastructure/cognitolambda/node_modules | |
public/* | ||
/frontend/tsconfig.tsbuildinfo | ||
.idea/ | ||
.env |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
import boto3 | ||
import sys | ||
from os import path | ||
|
||
try: | ||
pcui_stack_name = sys.argv[1] | ||
except: | ||
raise TypeError("Please provide a base PCUI stack name") | ||
|
||
client = boto3.client('cloudformation') | ||
|
||
def get_nested_stack_name(logical_id): | ||
nested_stack = client.describe_stack_resource(StackName=pcui_stack_name, LogicalResourceId=logical_id) | ||
return nested_stack['StackResourceDetail']['PhysicalResourceId'] | ||
|
||
def get_output(stack_name, output_key): | ||
pcui_stack = client.describe_stacks(StackName=stack_name) | ||
for output in pcui_stack['Stacks'][0]['Outputs']: | ||
if output['OutputKey'] == output_key: | ||
return output['OutputValue'] | ||
|
||
pc_api_stack_name = get_nested_stack_name('ParallelClusterApi') | ||
pcui_cognito_stack_name = get_nested_stack_name('Cognito') | ||
outpath = f"{path.dirname(path.dirname(__file__))}/.env" | ||
|
||
with open(outpath, 'w') as file: | ||
file.write(f"export API_BASE_URL={get_output(pc_api_stack_name, 'ParallelClusterApiInvokeUrl')}\n") | ||
file.write("export ENV=dev\n") | ||
file.write(f"export SECRET_ID={get_output(pcui_stack_name, 'UserPoolClientSecretName')}\n") | ||
file.write("export SITE_URL=http://localhost:5001\n") | ||
file.write(f"export AUDIENCE={get_output(pcui_stack_name, 'AppClientId')}\n") | ||
file.write(f"export AUTH_PATH={get_output(pcui_cognito_stack_name, 'UserPoolAuthDomain')}") | ||
|
||
print(f"Wrote to {outpath}") |