121 lines
3.6 KiB
Python
Raw Permalink Normal View History

Add Workshop E2E (#253) * feat: e2e tutorial lab5 * docs: Add README.md for 05-AgentCore Observability lab * feat: Add Lab 6 of E2E tutorial * fix: Fix Agent ECR repository typo * docs: Update Lab 6 Guidelines * feat: cleanup guardrails * docs: fix step name * added lab4 * Add Lab 3 Identity Notebook and README * added memory and updated lab 1 * pushing all of the helper files from original use case. Remove as needed * feat: update lab1 helper file * chore: restructure utils * feat: update memory helper * chore: restructure identity * chore: append to agent definition from the helper * Renamed agentcore identity to lab6 * Renamed Gateway notebook to Lab 3 and reviewed with fixes * Fixed typo in delete_memory * Lab 1: review and minor fixes * Lab 1: cleanup * Lab 2: refactored * fix: change model to Claude 3.7 * added TODOs * updated lab1 notebook * update runtime intro * refactor utils file * minor_update to memory * memory return client * revert change. * feat: update runtime lab * feat: add helper for bedrock guardrails * fix: fix typos * docs: minor update * update lab1 tools * update memory * update - runtime * updated lab3 + lambda * removed outputs * changed sh * removed zip * added one missing piece * chore: rm observability old lab * Updates to Lab6 Identity * Updates to Lab6 Identity * updated arch. diagram * update docs lab1 * rename-lab-5-6 * update arch doc * lab 03 * fixed lab 3 docs * Fix Lab 4 * Lab 7 frontend * Fix lab7 * Fix prereq issues and update gitignore * adding lab 3 tool removal * removed checkpoints * merged * chore: Update Lab 4 documentation * fix: Update AgentCore IAM Role to access memory * Lab 7 fixed invoke to runtime * minor changes * removed guardrails + minor edits * Deleting files and folders. * Rename, Refactor and deletion Added sagemaker_helper * fixing Client * Removing guardrails code * remove unused arch * remove unused files * updating lab01 * remove policies * updating lab02 * docs: Update lab 4 markdown * chore: Update Lab 4 * update cleanup * cleaning up DS_Store files * frontend * updates to lab1 notebook * updating architectures * Lab5: fixed response formatting in streamlit app * updating lab3 * updated lab3 * Lab 5 and Lab 6 and Helper Scripts Updates Lab 5: Added the architecture diagram Lab 6: Updated the notebook Utils: Added helper functions Sagemaker_helper: Cosmetic Updates * Updating lab 4 * removing clean up from lab 3 * added lab3 changes * Streamlit Fixes, Cosmetic Updates, Notebook Updates * add maira's changes * update lab2+3 * minor updates * sync labs * fix runtime docs * refactoring end-to-end tutorials * remove guardrail ss --------- Co-authored-by: Aleksei Iancheruk <aianch@amazon.fr> Co-authored-by: EugeneSel <youdjin.sel15@gmail.com> Co-authored-by: Aidan Ricci <riaidan@amazon.com> Co-authored-by: Achintya <pinnintiachintya@gmail.com> Co-authored-by: naresh rajaram <nareshrd@amazon.com> Co-authored-by: Lorenzo Micheli <lorenzo.micheli@gmail.com> Co-authored-by: Achintya <apinnint@amazon.com> Co-authored-by: HT <hardikvt@amazon.com> Co-authored-by: HT <hardik.thakkar00@gmail.com> Co-authored-by: Maira Ladeira Tanke <mttanke@amazon.com>
2025-08-14 22:52:33 -04:00
import boto3
import json
import yaml
import os
from typing import Dict, Any
def get_ssm_parameter(name: str, with_decryption: bool = True) -> str:
ssm = boto3.client("ssm")
response = ssm.get_parameter(Name=name, WithDecryption=with_decryption)
return response["Parameter"]["Value"]
def put_ssm_parameter(
name: str, value: str, parameter_type: str = "String", with_encryption: bool = False
) -> None:
ssm = boto3.client("ssm")
put_params = {
"Name": name,
"Value": value,
"Type": parameter_type,
"Overwrite": True,
}
if with_encryption:
put_params["Type"] = "SecureString"
ssm.put_parameter(**put_params)
def delete_ssm_parameter(name: str) -> None:
ssm = boto3.client("ssm")
try:
ssm.delete_parameter(Name=name)
except ssm.exceptions.ParameterNotFound:
pass
def load_api_spec(file_path: str) -> list:
with open(file_path, "r") as f:
data = json.load(f)
if not isinstance(data, list):
raise ValueError("Expected a list in the JSON file")
return data
def get_aws_region() -> str:
session = boto3.session.Session()
return session.region_name
def get_aws_account_id() -> str:
sts = boto3.client("sts")
return sts.get_caller_identity()["Account"]
def get_cognito_client_secret() -> str:
client = boto3.client("cognito-idp")
response = client.describe_user_pool_client(
UserPoolId=get_ssm_parameter("/app/customersupport/agentcore/userpool_id"),
ClientId=get_ssm_parameter("/app/customersupport/agentcore/machine_client_id"),
)
return response["UserPoolClient"]["ClientSecret"]
def read_config(file_path: str) -> Dict[str, Any]:
"""
Read configuration from a file path. Supports JSON, YAML, and YML formats.
Args:
file_path (str): Path to the configuration file
Returns:
Dict[str, Any]: Configuration data as a dictionary
Raises:
FileNotFoundError: If the file doesn't exist
ValueError: If the file format is not supported or invalid
yaml.YAMLError: If YAML parsing fails
json.JSONDecodeError: If JSON parsing fails
"""
if not os.path.exists(file_path):
raise FileNotFoundError(f"Configuration file not found: {file_path}")
# Get file extension to determine format
_, ext = os.path.splitext(file_path.lower())
try:
with open(file_path, "r", encoding="utf-8") as file:
if ext == ".json":
return json.load(file)
elif ext in [".yaml", ".yml"]:
return yaml.safe_load(file)
else:
# Try to auto-detect format by attempting JSON first, then YAML
content = file.read()
file.seek(0)
# Try JSON first
try:
return json.loads(content)
except json.JSONDecodeError:
# Try YAML
try:
return yaml.safe_load(content)
except yaml.YAMLError:
raise ValueError(
f"Unsupported configuration file format: {ext}. "
f"Supported formats: .json, .yaml, .yml"
)
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON in configuration file {file_path}: {e}")
except yaml.YAMLError as e:
raise ValueError(f"Invalid YAML in configuration file {file_path}: {e}")
except Exception as e:
raise ValueError(f"Error reading configuration file {file_path}: {e}")