diff --git a/cfn/3-ec2-streamlit-template.yaml b/cfn/3-ec2-streamlit-template.yaml index 0e49d04..7a66fee 100644 --- a/cfn/3-ec2-streamlit-template.yaml +++ b/cfn/3-ec2-streamlit-template.yaml @@ -197,7 +197,7 @@ Resources: apt-get update -y apt-get upgrade -y apt-get install -y python3-pip git ec2-instance-connect - git clone https://github.com/build-on-aws/bedrock-agents-streamlit.git /home/ubuntu/app + git clone https://github.com/jossai87/bedrock-agents-streamlit-1.git /home/ubuntu/app pip3 install -r /home/ubuntu/app/streamlit_app/requirements.txt cd /home/ubuntu/app/streamlit_app diff --git a/streamlit_app/invoke_agent.py b/streamlit_app/invoke_agent.py index 7003336..ab1cf47 100644 --- a/streamlit_app/invoke_agent.py +++ b/streamlit_app/invoke_agent.py @@ -11,7 +11,17 @@ from botocore.credentials import Credentials from requests import request -ssm = boto3.client('ssm') +# --------------------------------------------------------------------- +# REGION CONFIGURATION: +# --------------------------------------------------------------------- +theRegion = "us-west-2" +os.environ["AWS_REGION"] = theRegion + +# Configure boto3 to use the specified region +boto3.setup_default_session(region_name=theRegion) + +# Now create the SSM client with the region explicitly specified +ssm = boto3.client('ssm', region_name=theRegion) # --------------------------------------------------------------------- # Replace with your actual Agent ID and Alias ID below: @@ -24,13 +34,6 @@ #agentId = ssm.get_parameter(Name='/agent-id', WithDecryption=True)['Parameter']['Value'] #valid if CFN infrastructure templates were ran #agentAliasId = ssm.get_parameter(Name='/alias-id', WithDecryption=True)['Parameter']['Value'] #valid if CFN infrastructure templates were ran - -# --------------------------------------------------------------------- -# REGION CONFIGURATION: -# --------------------------------------------------------------------- -theRegion = "us-west-2" -os.environ["AWS_REGION"] = theRegion - # --------------------------------------------------------------------- # HELPER FUNCTION TO GET AWS CREDENTIALS SAFELY # --------------------------------------------------------------------- @@ -39,7 +42,7 @@ def get_frozen_credentials(): Safely obtain frozen AWS credentials from the current Boto3 Session. Raise an error if credentials are not found to clarify what's missing. """ - session = Session() + session = Session(region_name=theRegion) creds = session.get_credentials() if not creds: raise EnvironmentError( @@ -226,4 +229,3 @@ def lambda_handler(event, context): "status_code": 500, "body": json.dumps({"error": str(e)}) } -