1
0
mirror of synced 2026-08-05 11:07:15 +00:00
Files
Bharathi Srinivasan 3a8d5352da Restructure use cases (#1653)
* restructure 02-use-cases into three agent-type categories

Reorganizes all 27 use case samples into category subfolders aligned
with the AgentCore GTM workload definitions:

- 01-conversational-agents/ (19 samples): user-facing agents with
  streaming, user OAuth, and session/long-term memory
- 02-automation-agents/ (4 samples): event-driven agents with service
  identity and stateless execution
- 03-coding-assistants/ (3 samples): developer tools with sandboxed
  execution and project-scoped memory

Other changes:
- Moves okta-auth-three-tier-end-to-end-demo to
  01-features/05-authenticate-and-authorize (identity pattern, not a
  use case)
- Adds 02-use-cases/README.md with category index and sample table
- Adds category README for each subfolder, aligned with GTM definitions,
  no em-dashes
- Adds use-case-assessment.md with per-sample scoring, recommendations,
  and a starter toolkit migration list (18 of 27 samples need migrating)
- Fixes all cross-folder relative links broken by the restructure
  (LICENSE, LOCAL_DEVELOPMENT.md, AGENTCORE_DEPLOYMENT.md)

* cull low-quality conversational agent samples and reorganise identity demos

Reviewed all 19 conversational agent samples against actual AgentCore
feature usage, blog post references, and code quality. Removed 9 samples
that did not meet the bar and moved 2 identity-pattern demos to the
correct location.

Dropped from 01-conversational-agents/:
- gateway-schema-support-agent: misclassified coding agent, 82-line README,
  only 1 real feature, no blog post
- slide-deck-generator-memory-agent: narrow use case, no blog post,
  deprecated starter toolkit, 5 features
- local-prototype-to-agentcore: claimed 9 features, only 3 in code,
  tutorial format belongs in 01-tutorials/
- role-based-hr-data-agent: no blog post, deprecated starter toolkit,
  Cedar pattern needs full rebuild to be useful
- A2A-realestate-agentcore-multiagents: claimed 10 features, only 3 in
  code (Runtime, Cognito, A2A), no blog post
- cost-optimization-agent: only Runtime in code, notebook-driven, no
  blog post
- DB-performance-analyzer: only Gateway + Cognito in code, no blog post
- farm-management-advisor: notebook-only, mixed deprecated/native SDK,
  191-line README, no blog post

Moved to 01-features/05-authenticate-and-authorize/:
- auth0-multi-agent-obo: RFC 8693 OBO token exchange is an identity
  pattern, not a use case; sits alongside okta and entra OBO samples
- okta-auth-three-tier-end-to-end-demo: (previous commit)

Other changes:
- Rename 02-automation-agents/ to 02-workflow-automation-agents/
- Update use-case-assessment.md with DROPPED/MOVED entries for all
  removed samples
- Update all README counts and sample tables
- Add auth0-multi-agent-obo to identity README folder table and
  auth pattern quick reference

* update use-case-assessment with decisions, actual features, and authors contacted

* untrack use-case-assessment.md (local only)

* fix CONTRIBUTING.md relative paths broken by use-cases restructure

Samples moved one level deeper (into category subfolders) so
../../CONTRIBUTING.md no longer resolves to the repo root.
Updated to ../../../CONTRIBUTING.md in three files:
- 01-conversational-agents/customer-support-assistant/README.md
- 02-workflow-automation-agents/event-driven-claims-agent/README.md
- 03-coding-assistants/claude-code-gateway-mcp-server/README.md

* fix: address checkov security findings in CloudFormation templates

AWS-operations-agent mcp-tool-template.yaml and mcp-tool-template-zip.yaml:
- Scope IAM wildcard resources to account/region-specific ARNs
  (lambda:InvokeFunction, iam:PassRole, s3:*, logs:*)
- Split S3 permissions into bucket-level and object-level statements
- Scope bedrock:InvokeModel to foundation-model ARN pattern
- Add KMS keys for Lambda env var encryption (CKV_AWS_173) and CloudWatch
  log group encryption (CKV_AWS_158)
- Add SQS dead letter queue and DeadLetterQueue config (CKV_AWS_116)
- Add ReservedConcurrentExecutions (CKV_AWS_115)
- Add checkov:skip for VPC (CKV_AWS_117) - demo function, VPC not required

customer-support-assistant cognito.yaml:
- Scope logs resource to account/region ARN prefix
- Scope cognito-idp:AdminAddUserToGroup to UserPool ARN
- Add SQS DLQ and DeadLetterConfig to PostSignupFunction (CKV_AWS_116)
- Add ReservedConcurrentExecutions (CKV_AWS_115)
- Add checkov:skip for VPC (CKV_AWS_117) - Cognito trigger, VPC not needed

customer-support-assistant infrastructure.yaml:
- Add KMS CMK and SSESpecification to WarrantyTable and CustomerProfileTable
  (CKV_AWS_119)
- Scope logs resource to account/region ARN prefix
- Add SQS DLQ and DeadLetterConfig to PopulateDataFunction (CKV_AWS_116)
- Add ReservedConcurrentExecutions (CKV_AWS_115)
- Add checkov:skip for VPC (CKV_AWS_117) - CFn custom resource, VPC not needed

* style: apply ruff formatting across all Python files

* remove customer-support-assistant; keep vpc variant only

* fix: resolve ruff lint errors to pass CI python-lint check

- Auto-fix F541 (f-strings without placeholders) and E401 (multiple imports)
- Extend root pyproject.toml ignore list with E722, F401, F811, F841
  (pre-existing patterns acceptable in a samples/tutorial repository)
- Add E722 to SRE-agent pyproject.toml ignore list (bare-except in server code)

* clean up readmes

* fix: resolve CodeQL security findings

lakehouse-agent (Python):
- Add codeql suppression comments on intentional clear-text logging of
  setup/debug info in deployment scripts (clear-text-logging-sensitive-data)
- Add codeql suppression on .env file write in deprecated write_to_env
  method (clear-text-storage-of-sensitive-data)
- Add codeql suppression on HMAC-SHA256 usage in streamlit_app.py;
  this is Cognito SECRET_HASH computation, not password hashing
  (weak-sensitive-data-hashing)

visa-b2b-account-payable-agent (TypeScript/JavaScript):
- Add express-rate-limit middleware to all /api/ routes in index.ts
  and lambda.ts (missing-rate-limiting)
- Fix CORS origin in lambda.ts to default to localhost instead of
  wildcard '*' (permissive-cors)
- Replace Math.random() with crypto.randomBytes() in visa-stubs
  for cryptographically secure card number generation (insecure-randomness)

workshops (Python):
- Add codeql suppression on user_pool_id logging in cognito_setup.py
  cleanup function (clear-text-logging-sensitive-data)

* fix: eliminate ReDoS in text-to-python-ide regex against user input

Replace lazy .+? quantifiers with negated character classes [^"\']{0,500}
in the input() call extractor pattern. The original pattern could
catastrophically backtrack on adversarial strings submitted as user code.
Negated classes cannot backtrack across the excluded characters, making
the match linear regardless of input content.

* style: ruff format long codeql suppression comment lines

Lines with inline codeql suppression comments exceeded the 120-char
limit; ruff reformats them by wrapping the expression and moving the
comment to the closing parenthesis line.
2026-06-12 14:37:42 -07:00
..
2026-06-12 14:37:42 -07:00

Basic AgentCore Runtime - Terraform

This pattern demonstrates the simplest deployment of an AgentCore Runtime using Terraform. It creates a basic agent without additional tools like Memory, Code Interpreter, or Browser.

Table of Contents

Overview

This Terraform configuration creates a minimal AgentCore deployment that includes:

  • AgentCore Runtime: Hosts a simple Strands agent
  • ECR Repository: Stores the Docker container image
  • IAM Roles: Provides necessary permissions
  • CodeBuild Project: Automatically builds the ARM64 Docker image

This makes it ideal for:

  • Learning AgentCore basics with Terraform
  • Quick prototyping and experimentation
  • Understanding the core deployment pattern
  • Building a foundation before adding complexity

Architecture

Architecture Diagram

What's Included

This Terraform configuration creates:

  • S3 Bucket: Stores agent source code for version-controlled builds
  • ECR Repository: Container registry for the agent Docker image
  • CodeBuild Project: Automated Docker image building and pushing
  • IAM Roles: Execution roles for the agent and CodeBuild
  • AgentCore Runtime: Serverless agent runtime with the deployed container

Agent Code Management

The agent-code/ directory contains your agent's source files:

  • basic_agent.py - Agent implementation
  • Dockerfile - Container configuration
  • requirements.txt - Python dependencies

Automatic Change Detection:

  • Terraform archives the agent-code/ directory
  • Uploads to S3 with MD5-based versioning
  • CodeBuild pulls from S3 and builds the Docker image
  • Any changes to files trigger automatic rebuild (new files, modifications, deletions)

Prerequisites

Required Tools

  1. Terraform (>= 1.6)

    Note: brew install terraform provides v1.5.7 (deprecated). Use tfenv or direct download for >= 1.6.

  2. AWS CLI (configured with credentials)

    aws configure
    
  3. Python 3.11+ (for testing scripts)

    python --version  # Verify Python 3.11 or later
    pip install boto3
    
  4. Docker (for local testing, optional)

AWS Account Requirements

  • AWS Account with appropriate permissions
  • Access to Amazon Bedrock models

Quick Start

1. Configure Variables

Copy the example variables file and customize:

cp terraform.tfvars.example terraform.tfvars

Edit terraform.tfvars with your preferred values.

2. Initialize Terraform

See State Management Options in the main README for detailed guidance on local vs. remote state.

Quick start with local state:

terraform init

For team collaboration, use remote state - see the main README for setup instructions.

3. Review the Plan

terraform plan

4. Deploy

Method 1: Using Deploy Script (Recommended)

Make the script executable (first-time only):

chmod +x deploy.sh

Then deploy:

./deploy.sh

The deploy script:

  • Validates Terraform configuration
  • Shows deployment plan
  • Prompts for confirmation
  • Applies changes

Method 2: Direct Terraform Commands

terraform apply

When prompted, type yes to confirm the deployment.

Note: The deployment process includes:

  1. Creating ECR repository
  2. Building Docker image via CodeBuild
  3. Creating AgentCore Runtime

Total deployment time: ~3-5 minutes

5. Get Outputs

After deployment completes:

terraform output

Example output:

agent_runtime_id = "AGENT1234567890"
agent_runtime_arn = "arn:aws:bedrock-agentcore:<us-west-2>:123456789012:agent-runtime/AGENT1234567890"
ecr_repository_url = "123456789012.dkr.ecr.us-west-2.amazonaws.com/agentcore-basic-basic-agent"

Testing the Agent

Prerequisites for Testing

Before testing, ensure you have the required packages installed:

Option A: Using uv (Recommended)

uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install boto3  # Required for agent invocation

Option B: System-wide installation

pip install boto3  # Required for agent invocation

Note: boto3 is required for the test script to invoke the agent runtime via AWS API.

# Run the test suite
python test_basic_agent.py $(terraform output -raw agent_runtime_arn)

Option 2: Using AWS CLI

# Get the runtime ARN from outputs
RUNTIME_ARN=$(terraform output -raw agent_runtime_arn)

# Invoke the agent
aws bedrock-agentcore invoke-agent-runtime \
  --agent-runtime-arn $RUNTIME_ARN \
  --qualifier DEFAULT \
  --payload $(echo '{"prompt": "Hello, introduce yourself"}' | base64) \
  response.json

# View the response
cat response.json | jq -r '.response'

Option 3: Using AWS Console

  1. Navigate to Amazon Bedrock console
  2. Go to AgentCore → Runtimes
  3. Select your runtime
  4. Use the "Test" feature to send queries

Sample Queries

Try these queries to test your basic agent:

  1. Simple Math:

    {"prompt": "What is 2+2?"}
    
  2. General Knowledge:

    {"prompt": "What is the capital of France?"}
    
  3. Explanation Request:

    {"prompt": "Explain what Amazon Bedrock is in simple terms"}
    
  4. Creative Task:

    {"prompt": "Write a haiku about cloud computing"}
    

Customization

Modify Agent Code

Edit files in agent-code/ and deploy:

  • basic_agent.py - Agent logic and system prompt
  • Dockerfile - Container configuration
  • requirements.txt - Python dependencies

Changes are automatically detected and trigger rebuild. Run terraform apply to deploy.

Environment Variables

Add to terraform.tfvars:

environment_variables = {
  LOG_LEVEL = "DEBUG"
}

Network Mode

Set network_mode = "PRIVATE" for VPC deployment (requires additional VPC configuration).

File Structure

basic-runtime/
├── main.tf                      # AgentCore runtime resource
├── variables.tf                 # Input variables
├── outputs.tf                   # Output values
├── versions.tf                  # Provider configuration
├── iam.tf                       # IAM roles and policies
├── s3.tf                        # S3 bucket for source code
├── ecr.tf                       # ECR repository
├── codebuild.tf                 # Docker build automation
├── buildspec.yml                # CodeBuild build specification
├── terraform.tfvars.example     # Example configuration
├── backend.tf.example           # Remote state example
├── test_basic_agent.py          # Automated test script
├── agent-code/                  # Agent source code
│   ├── basic_agent.py          # Agent implementation
│   ├── Dockerfile              # Container configuration
│   └── requirements.txt        # Python dependencies
├── scripts/                     # Build automation scripts
│   └── build-image.sh          # CodeBuild trigger & verification
├── deploy.sh                    # Deployment helper script
├── destroy.sh                   # Cleanup helper script
├── .gitignore                   # Git ignore patterns
└── README.md                    # This file

Troubleshooting

CodeBuild Fails

If the Docker build fails:

  1. Check CodeBuild logs:

    aws codebuild batch-get-builds \
      --ids $(terraform output -raw codebuild_project_name) \
      --region us-west-2
    
  2. Common issues:

    • Network connectivity issues
    • ECR authentication problems
    • Python dependency conflicts

Runtime Creation Fails

If the runtime creation fails:

  1. Verify the Docker image exists:

    aws ecr describe-images \
      --repository-name $(terraform output -raw ecr_repository_url | cut -d'/' -f2) \
      --region us-west-2
    
  2. Check IAM role permissions

  3. Verify Bedrock AgentCore service quotas

Agent Invocation Fails

If invoking the agent fails:

  1. Check runtime status in AWS Console
  2. Review CloudWatch Logs for the runtime
  3. Verify Bedrock model access permissions

Cleanup

Destroy All Resources

Make the script executable (first-time only):

chmod +x destroy.sh

Then cleanup:

./destroy.sh

Or use Terraform directly:

terraform destroy

Verify Cleanup

Confirm all resources are deleted:

# Check ECR repositories
aws ecr describe-repositories --region us-west-2 | grep agentcore-basic

# Check AgentCore runtimes
aws bedrock-agentcore list-agent-runtimes --region us-west-2

Pricing

For current pricing information, please refer to:

Note: Actual costs depend on your usage patterns, AWS region, and specific services consumed.

Next Steps

Explore Other Patterns

Resources

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.