Note
This is a sample project and work in progress. Use it as a reference for building AI agents with Amazon Bedrock Agent Core.
An AI agent that analyzes your AWS Lambda functions and generates cost optimization reports. It discovers AWS Lambda resources, collects metrics, identifies savings opportunities, and produces detailed recommendations.
The agent runs a two-phase workflow:
- Analysis Phase: Discovers AWS Lambda functions, collects Amazon CloudWatch metrics and logs, analyzes memory usage and invocation patterns, identifies optimization opportunities
- Report Phase: Generates a cost optimization report with specific recommendations, estimated savings, implementation steps, and supporting evidence
Results are saved to Amazon Simple Storage Service (Amazon S3) and tracked in Amazon DynamoDB for audit trails.
- Agent Runtime: Python agent using Strands Agents and Amazon Bedrock models
- Orchestration: Step Functions workflow triggered by EventBridge (scheduled or manual)
- Storage: Amazon S3 for reports, Amazon DynamoDB for event journaling
- Infrastructure: AWS CDK (TypeScript) for deployment
The diagram shows the agent workflow with 4 tools:
- use_aws tool: Collects cost data, AWS Lambda logs, and AWS Lambda configurations from your AWS account
- calculator tool: Performs time range calculations and cost computations
- storage tool: Saves analysis results and final reports to Amazon S3
- journal tool: Records workflow events to Amazon DynamoDB for audit trails
The Analysis Agent uses all 4 tools to discover resources and analyze costs. The Report Agent uses storage and journal tools to generate reports. Amazon Bedrock provides the AI model powering both agents.
In order to deploy the agent you will need to have the following tools installed on your machine:
- Python 3.12+ - Download Python
- uv - Python package manager - Installation guide
- Node.js 20+ - Required for AWS CDK - Download Node.js
- AWS CLI - Installation guide
Configure AWS credentials:
aws configure-
Install dependencies:
make setup
-
Deploy to AWS (first time only):
make cdk-bootstrap
-
Enable AgentCore observability (one-time setup):
To view metrics, spans, and traces generated by the AgentCore service, you need to enable Amazon CloudWatch Transaction Search. Follow the observability configuration guide to complete this setup.
-
Deploy the stack:
make cdk-deploy
-
Trigger the agent:
make trigger-workflow
The agent will analyze your AWS Lambda functions and save a cost optimization report to Amazon S3.
. ├── src/ │ ├── agents/ # Agent code and prompts │ ├── tools/ # Custom tools (journal, storage) │ └── shared/ # Shared utilities ├── infra/ # CDK infrastructure (TypeScript) │ ├── lib/ # Stack definitions │ └── lambda/ # Lambda function handlers ├── tests/ # Test files └── Makefile # Common commands Set these environment variables (or use defaults):
ENVIRONMENT: Environment name (default:dev)VERSION: Version tag (default:v1)MODEL_ID: Amazon Bedrock model ID (default: Claude Sonnet 4)TTL_DAYS: Amazon DynamoDB record retention (default:30)
Deploy changes:
make cdk-deploy # Full deployment make cdk-hotswap # Fast AWS Lambda-only updates make cdk-watch # Auto-deploy on file changesRun the agent locally for testing:
Terminal 1 - Start the agent:
make run-agent-localTerminal 2 - Invoke the agent:
make invoke-agent-localThe agent runs on http://localhost:8080 with reload. Logs appear in Terminal 1.
Scheduled: Runs daily at 6am UTC (configured in EventBridge)
Manual: Trigger anytime:
make trigger-workflowCustom trigger:
aws events put-events --entries '[{ "Source": "manual-trigger", "DetailType": "execute-agent", "Detail": "{}" }]'Check the Step Functions console for workflow execution status. View reports in the Amazon S3 bucket (output in CDK deployment). Query Amazon DynamoDB for event history and audit trails.
Run tests:
make test # All tests make check # Linting and formattingRemove AWS resources:
make cdk-destroyRemove local artifacts:
make cleanAgent fails to start: Check AWS credentials are configured and have necessary permissions (AWS Lambda, Amazon CloudWatch, Amazon S3, Amazon DynamoDB, Amazon Bedrock).
No AWS Lambda functions found: The agent analyzes AWS Lambda functions in us-east-1. Ensure you have functions in that region or modify the region in the code.
Deployment fails: Run make cdk-bootstrap first if this is your first CDK deployment in the account/region.
See CONTRIBUTING.md for guidelines.
See CONTRIBUTING for security issue reporting.
This library is licensed under the MIT-0 License. See the LICENSE file.
