1
0
mirror of synced 2026-05-22 22:53:35 +00:00
David Kaleko 89891fcba5 Add AWS CDK implementation for existing CFN examples (#536)
* feat: Add AWS CDK implementation for basic AgentCore runtime deployment

This commit introduces a comprehensive CDK alternative to the existing CloudFormation
basic-runtime sample, providing a cleaner and more maintainable Infrastructure as Code
approach for deploying Amazon Bedrock AgentCore resources.

- **Complete CDK stack** (`basic_runtime_stack.py`) with proper construct separation
- **Dedicated IAM role construct** (`infra-utils/agentcore_role.py`) for reusability
- **Custom Lambda function** (`infra-utils/build_trigger_lambda.py`) for CodeBuild automation
- **S3 asset-based source packaging** eliminating Docker dependency for users
- **ARM64 CodeBuild integration** with automated container image building
- **Comprehensive documentation** matching CloudFormation sample structure

- Uses S3 assets instead of inline code for better maintainability
- Separates infrastructure utilities into dedicated `infra-utils/` directory
- Implements proper CDK patterns with construct separation
- Provides cleaner deployment experience (~5-10 min vs ~10-15 min)

- **Basic Strands agent** (`agent-code/basic_agent.py`) with simple Q&A functionality
- **ARM64 Dockerfile** optimized for AgentCore runtime requirements
- **Proper dependency management** with isolated requirements

- Updated title to reflect both CloudFormation and CDK options
- Added comprehensive CDK section with architecture highlights
- Included CDK prerequisites with version requirements (CDK 2.218.0+)
- Updated repository structure to show new CDK directory layout
- Added installation commands for required CDK dependencies

- Complete documentation following CloudFormation sample structure
- Detailed prerequisites, deployment, testing, and cleanup instructions
- Sample queries and troubleshooting sections
- Architecture explanation and use case descriptions

- **CDK 2.218.0+** required for BedrockAgentCore construct support
- **Python 3.8+** and **constructs>=10.0.79** for proper CDK functionality
- **S3 assets** for source code packaging without size limitations

- ECR repository for container image storage
- CodeBuild project with ARM64 support for automated builds
- Lambda function for build orchestration and completion waiting
- AgentCore Runtime with proper IAM permissions and networking
- Custom resource for deployment automation

-  Successfully deployed and tested in AWS environment
-  Verified agent functionality with sample queries
-  Confirmed clean resource cleanup with `cdk destroy`

- Added David Kaleko to CONTRIBUTORS.md

This implementation provides a modern, maintainable alternative to CloudFormation
while maintaining feature parity and following AWS CDK best practices.

* fix: Resolve CDK Lambda import issues and reorganize infrastructure utilities

This commit fixes critical Lambda function import errors that were preventing
the CDK stack deployment from completing, and reorganizes the infrastructure
utilities for better Python module compatibility.

- **Root cause**: `cfnresponse` module is only available for inline CloudFormation
  Lambda code, not when using CDK's `Code.from_asset()` approach
- **Solution**: Embedded the standard AWS-provided cfnresponse functionality
  directly into the Lambda function to eliminate import dependencies
- **Impact**: Custom resource now properly signals CloudFormation completion/failure

- **Renamed**: `infra-utils/` → `infra_utils/` for proper Python module imports
- **Fixed**: Lambda handler path to use correct Python module notation
- **Updated**: Import statements to use underscore-based directory name

- Embedded cfnresponse class with SUCCESS/FAILED constants and send() method
- Added comprehensive comments explaining why local cfnresponse is necessary
- Maintains full compatibility with CloudFormation custom resource protocol
- Proper error handling and CloudWatch logging integration

- Updated Lambda handler path: `infra_utils.build_trigger_lambda.handler`
- Fixed import statements for renamed directory structure
- Removed conditional BedrockAgentCore imports (always available in CDK 2.218.0+)

- Moved infrastructure utilities to properly named Python package
- Added package `__init__.py` for proper module structure
- Maintained clean separation between infrastructure and agent code

-  Resolves hanging CloudFormation deployments
-  Custom resource now properly waits for CodeBuild completion
-  Stack deployment completes successfully end-to-end
-  Maintains compatibility with existing CloudFormation approach

- Verified Lambda function executes without import errors
- Confirmed CodeBuild triggering and monitoring functionality
- Validated complete stack deployment cycle

This fix ensures the CDK implementation works reliably and follows Python
packaging best practices while maintaining the same deployment behavior
as the CloudFormation equivalent.

* Minor README update

* Dockerfile updates including a health check to fix all ASH security scan warnings

* Readme updates in accordance with PR feedback

* feat: Add CDK implementation for end-to-end weather agent

- Complete CDK stack for weather-based activity planning agent
- Includes browser tool, code interpreter, memory, and S3 storage
- Fixed IAM permissions for bedrock-agentcore services
- Added proper CloudFormation response handling for custom resources
- Comprehensive documentation with deployment and testing instructions
- Production-ready infrastructure with monitoring and best practices

* Add CDK implementation for multi-agent runtime

Convert CloudFormation multi-agent-runtime example to CDK with:
- Dual agent architecture (orchestrator + specialist)
- Agent-to-agent communication via bedrock-agentcore:InvokeAgentRuntime
- Separate ECR repos and CodeBuild projects for each agent
- IAM roles with proper cross-agent invocation permissions
- Custom resource Lambda for build triggering
- Comprehensive documentation and test script

Tested and validated: orchestrator correctly delegates complex queries to specialist agent while handling simple queries directly.

* README updates to make sure CDK readmes parallel that of cloudformation, copied architecture diagrams over because they're the same

* Add CDK implementation for MCP server AgentCore runtime

Convert CloudFormation mcp-server-agentcore-runtime example to CDK with:
- MCP server with FastMCP and three tools (add_numbers, multiply_numbers, greet_user)
- Cognito JWT authentication with pre-created test user
- ECR repository and CodeBuild project for ARM64 Docker image
- IAM roles with proper permissions for MCP protocol
- Custom Lambda functions for build triggering and password setting
- Architecture diagram and comprehensive documentation
- Test scripts for authentication and MCP tool validation

Tested and validated: MCP server successfully deployed with JWT auth, all three tools working correctly via MCP client.

* Reorganizing READMEs to avoid duplication, top level IaC README describes each example only once then links to both CFN and CDK versions of each

* Python linting fixes

---------

Signed-off-by: David Kaleko <5712203+kaleko@users.noreply.github.com>
2025-11-06 14:28:30 -03:00
2025-10-24 11:48:10 -04:00
2025-11-04 14:35:14 -05:00

Amazon Bedrock AgentCore Samples

Deploy and operate AI agents securely at scale - using any framework and model

GitHub commit activity GitHub open issues GitHub open pull requests License

DocumentationPython SDKStarter Toolkit Discord

Welcome to the Amazon Bedrock AgentCore Samples repository!

Amazon Bedrock AgentCore is both framework-agnostic and model-agnostic, giving you the flexibility to deploy and operate advanced AI agents securely and at scale. Whether youre building with Strands Agents, CrewAI, LangGraph, LlamaIndex, or any other framework—and running them on any Large Language Model (LLM)—Amazon Bedrock AgentCore provides the infrastructure to support them. By eliminating the undifferentiated heavy lifting of building and managing specialized agent infrastructure, Amazon Bedrock AgentCore lets you bring your preferred framework and model, and deploy without rewriting code.

This collection provides examples and tutorials to help you understand, implement, and integrate Amazon Bedrock AgentCore capabilities into your applications.

🎥 Video

Build your first production-ready AI agent with Amazon Bedrock AgentCore. Well take you beyond prototyping and show you how to productionize your first agentic AI application using Amazon Bedrock AgentCore.

📁 Repository Structure

📚 01-tutorials/

Interactive Learning & Foundation

This folder contains notebook-based tutorials that teach you the fundamentals of Amazon Bedrock AgentCore capabilities through hands-on examples.

The structure is divided by AgentCore component:

  • Runtime: Amazon Bedrock AgentCore Runtime is a secure, serverless runtime capability that empowers organizations to deploy and scale both AI agents and tools, regardless of framework, protocol, or model choice—enabling rapid prototyping, seamless scaling, and accelerated time to market

  • Gateway: AI agents need tools to perform real-world tasks—from searching databases to sending messages. Amazon Bedrock AgentCore Gateway automatically converts APIs, Lambda functions, and existing services into MCP-compatible tools so developers can quickly make these essential capabilities available to agents without managing integrations.

  • Memory: Amazon Bedrock AgentCore Memory makes it easy for developer to build rich, personalized agent experiences with fully-manged memory infrastructure and the ability to customize memory for your needs.

  • Identity: Amazon Bedrock AgentCore Identity provides seamless agent identity and access management across AWS services and third-party applications such as Slack and Zoom while supporting any standard identity providers such as Okta, Entra, and Amazon Cognito.

  • Tools: Amazon Bedrock AgentCore provides two built-in tools to simplify your agentic AI application development: Amazon Bedrock AgentCore Code Interpreter tool enables AI agents to write and execute code securely, enhancing their accuracy and expanding their ability to solve complex end-to-end tasks. Amazon Bedrock AgentCore Browser Tool is an enterprise-grade capability that enables AI agents to navigate websites, complete multi-step forms, and perform complex web-based tasks with human-like precision within a fully managed, secure sandbox environment with low latency

  • Observability: Amazon Bedrock AgentCore Observability helps developers trace, debug, and monitor agent performance through unified operational dashboards. With support for OpenTelemetry compatible telemetry and detailed visualizations of each step of the agent workflow, Amazon Bedrock AgentCore Observability enables developers to easily gain visibility into agent behavior and maintain quality standards at scale.

  • AgentCore end-to-end: In this tutorial we will move a customer support agent from prototype to production using Amazon Bedrock AgentCore services.

The examples provided as perfect for beginners and those looking to understand the underlying concepts before building AI Agents applications.

💡 02-use-cases/

End-to-end Applications

Explore practical use case implementations that demonstrate how to apply Amazon Bedrock AgentCore capabilities to solve real business problems.

Each use case includes complete implementation focused on the AgentCore components with detailed explanations.

🔌 03-integrations/

Framework & Protocol Integration

Learn how to integrate Amazon Bedrock AgentCore capabilities with popular Agentic frameworks such as Strands Agents, LangChain and CrewAI.

Set agent-to-agent communication with A2A and different multi-agent collaboration patterns. Integrate agentic interfaces and learn how to use Amazon Bedrock AgentCore with different entry points.

Running a Notebook

  1. Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Export/Activate required AWS Credentials for the notebook to run

  2. Register your virtual environment as a kernel for Jupyter notebook to use

python -m ipykernel install --user --name=notebook-venv --display-name="Python (notebook-venv)"

You can list your kernels using:

jupyter kernelspec list
  1. Run the notebook and ensure the correct kernel is selected
jupyter notebook path/to/your/notebook.ipynb

Important: After opening the notebook in Jupyter, make sure to select the correct kernel by going to KernelChange kernel → select "Python (notebook-venv)" to ensure your virtual environment packages are available.

Quick Start - Amazon Bedrock AgentCore Runtime

Step 1: Prerequisites

  • An AWS account with credentials configured (aws configure)
  • Python 3.10 or later
  • Docker or Finch installed and running - only for local development
  • Model Access: Anthropic Claude 4.0 enabled in Amazon Bedrock console
  • AWS Permissions:
    • BedrockAgentCoreFullAccess managed policy
    • AmazonBedrockFullAccess managed policy
    • Caller permissions: See detailed policy here

Step 2: Install and Create Your Agent

# Install both packages
pip install bedrock-agentcore strands-agents bedrock-agentcore-starter-toolkit

Create my_agent.py:

from bedrock_agentcore import BedrockAgentCoreApp
from strands import Agent

app = BedrockAgentCoreApp()
agent = Agent()

@app.entrypoint
def invoke(payload):
    """Your AI agent function"""
    user_message = payload.get("prompt", "Hello! How can I help you today?")
    result = agent(user_message)
    return {"result": result.message}

if __name__ == "__main__":
    app.run()

Create requirements.txt:

cat > requirements.txt << EOF
bedrock-agentcore
strands-agents
EOF

Step 3: Test Locally

# Start your agent
python my_agent.py

# Test it (in another terminal)
curl -X POST http://localhost:8080/invocations \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello!"}'

Success: You should see a response like {"result": "Hello! I'm here to help..."}

Step 4: Deploy to AWS

# Configure and deploy (auto-creates all required resources)
agentcore configure -e my_agent.py
agentcore launch

# Test your deployed agent
agentcore invoke '{"prompt": "tell me a joke"}'

Congratulations! Your agent is now running on Amazon Bedrock AgentCore Runtime!

Follow quickstart guides for Gatway, Identity, Memory, Observability, and builtin-tools.

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details on:

  • Adding new samples
  • Improving existing examples
  • Reporting issues
  • Suggesting enhancements

📄 License

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

Contributors

S
Description
Amazon Bedrock Agentcore accelerates AI agents into production with the scale, reliability, and security, critical to real-world deployment.
Readme 1.4 GiB
Languages
Jupyter Notebook 41.8%
Python 37.4%
TypeScript 8.2%
JavaScript 6.8%
Shell 3%
Other 2.6%