Skip to content

Commit 954436c

Browse files
committed
Retriece API from a CFN stack
1 parent 29168ef commit 954436c

File tree

1 file changed

+11
-1
lines changed
  • workshops/serverless-testing-workshop/demo-app

1 file changed

+11
-1
lines changed

workshops/serverless-testing-workshop/demo-app/urs-ui.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212
import uuid
1313
import time
1414
import requests
15+
import boto3
1516
import streamlit as st
1617
from streamlit_js_eval import streamlit_js_eval
1718

1819
# Initialize Contexts
1920
if 'api_endpoint_url' not in st.session_state:
20-
if os.path.isfile("config.json"):
21+
try:
22+
cfn_client = boto3.client('cloudformation')
23+
response = cfn_client.describe_stacks(StackName=os.environ.get('BACKEND_STACK_NAME','urs-backend'))
24+
for output in response['Stacks'][0]['Outputs']:
25+
if output['OutputKey'] == 'ApiEndpoint':
26+
st.session_state['api_endpoint_url'] = output['OutputValue']
27+
except:
28+
print("Failed to get API Endpoint from CloudFormation Stack")
29+
30+
if os.path.isfile("config.json") and 'api_endpoint_url' not in st.session_state:
2131
with open("config.json","r",encoding="utf-8") as f:
2232
app_config = json.load(f)
2333
st.session_state['api_endpoint_url'] = app_config["api_endpoint"].strip()

0 commit comments

Comments
 (0)