{"id":36442371,"url":"https://github.com/aws-samples/sample-agentic-cost-optimizer","last_synced_at":"2026-01-18T15:00:30.294Z","repository":{"id":326574949,"uuid":"1086436106","full_name":"aws-samples/sample-agentic-cost-optimizer","owner":"aws-samples","description":"Sample Agentic Cost Optimizer","archived":false,"fork":false,"pushed_at":"2026-01-15T09:54:31.000Z","size":1047,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-15T15:35:34.619Z","etag":null,"topics":["agent","agentcore","ai","aws","aws-lambda","bedrock","lambda","strands-agents"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit-0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aws-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-30T12:19:07.000Z","updated_at":"2026-01-15T09:54:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/aws-samples/sample-agentic-cost-optimizer","commit_stats":null,"previous_names":["aws-samples/sample-agentic-cost-optimizer"],"tags_count":0,"template":false,"template_full_name":"amazon-archives/__template_MIT-0","purl":"pkg:github/aws-samples/sample-agentic-cost-optimizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Fsample-agentic-cost-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Fsample-agentic-cost-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Fsample-agentic-cost-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Fsample-agentic-cost-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aws-samples","download_url":"https://codeload.github.com/aws-samples/sample-agentic-cost-optimizer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Fsample-agentic-cost-optimizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28538865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T14:59:57.589Z","status":"ssl_error","status_checked_at":"2026-01-18T14:59:46.540Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","agentcore","ai","aws","aws-lambda","bedrock","lambda","strands-agents"],"created_at":"2026-01-11T22:00:18.248Z","updated_at":"2026-01-18T15:00:30.232Z","avatar_url":"https://github.com/aws-samples.png","language":"Python","funding_links":[],"categories":["Community Projects"],"sub_categories":["For PyPI Packages"],"readme":"# Sample Agentic Cost Optimizer\n\n\u003e [!NOTE]\n\u003e This is a sample project and work in progress. Use it as a reference for building AI agents with Amazon Bedrock Agent Core.\n\nAn 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.\n\n## What It Does\n\nThe agent runs a two-phase workflow:\n\n1. **Analysis Phase**: Discovers AWS Lambda functions, collects Amazon CloudWatch metrics and logs, analyzes memory usage and invocation patterns, identifies optimization opportunities\n2. **Report Phase**: Generates a cost optimization report with specific recommendations, estimated savings, implementation steps, and supporting evidence\n\nResults are saved to Amazon Simple Storage Service (Amazon S3) and tracked in Amazon DynamoDB for audit trails.\n\n## How It Works\n\n- **Agent Runtime**: Python agent using [Strands Agents](https://strandsagents.com/latest/) and Amazon Bedrock models\n- **Orchestration**: Step Functions workflow triggered by EventBridge (scheduled or manual)\n- **Storage**: Amazon S3 for reports, Amazon DynamoDB for event journaling\n- **Infrastructure**: AWS CDK (TypeScript) for deployment\n\n## Architecture\n\n![Architecture Diagram](docs/architecture_diagram.png)\n\nThe diagram shows the agent workflow with 4 tools:\n\n- **use_aws tool**: Collects cost data, AWS Lambda logs, and AWS Lambda configurations from your AWS account\n- **calculator tool**: Performs time range calculations and cost computations\n- **storage tool**: Saves analysis results and final reports to Amazon S3\n- **journal tool**: Records workflow events to Amazon DynamoDB for audit trails\n\nThe **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.\n\n## Prerequisites\n\nIn order to deploy the agent you will need to have the following tools installed on your machine:\n\n- **Python 3.12+** - [Download Python](https://www.python.org/downloads/)\n- **uv** - Python package manager - [Installation guide](https://docs.astral.sh/uv/getting-started/installation/)\n- **Node.js 20+** - Required for AWS CDK - [Download Node.js](https://nodejs.org/)\n- **AWS CLI** - [Installation guide](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)\n\nConfigure AWS credentials:\n\n```bash\naws configure\n```\n\n## Quick Start\n\n1. **Install dependencies**:\n   ```bash\n   make setup\n   ```\n\n2. **Deploy to AWS** (first time only):\n   ```bash\n   make cdk-bootstrap\n   ```\n\n3. **Enable AgentCore observability** (one-time setup):\n\n   To view metrics, spans, and traces generated by the AgentCore service, you need to enable Amazon CloudWatch Transaction Search. Follow the [observability configuration guide](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability-configure.html) to complete this setup.\n\n4. **Deploy the stack**:\n   ```bash\n   make cdk-deploy\n   ```\n\n5. **Trigger the agent**:\n   ```bash\n   make trigger-workflow\n   ```\n\nThe agent will analyze your AWS Lambda functions and save a cost optimization report to Amazon S3.\n\n## Project Structure\n\n```\n.\n├── src/\n│   ├── agents/          # Agent code and prompts\n│   ├── tools/           # Custom tools (journal, storage)\n│   └── shared/          # Shared utilities\n├── infra/               # CDK infrastructure (TypeScript)\n│   ├── lib/             # Stack definitions\n│   └── lambda/          # Lambda function handlers\n├── tests/               # Test files\n└── Makefile             # Common commands\n```\n\n## Configuration\n\nSet these environment variables (or use defaults):\n\n- `ENVIRONMENT`: Environment name (default: `dev`)\n- `VERSION`: Version tag (default: `v1`)\n- `MODEL_ID`: Amazon Bedrock model ID (default: Claude Sonnet 4)\n- `TTL_DAYS`: Amazon DynamoDB record retention (default: `30`)\n\n## Deployment\n\nDeploy changes:\n\n```bash\nmake cdk-deploy          # Full deployment\nmake cdk-hotswap         # Fast AWS Lambda-only updates\nmake cdk-watch           # Auto-deploy on file changes\n```\n\n## Local Development\n\nRun the agent locally for testing:\n\n**Terminal 1** - Start the agent:\n```bash\nmake run-agent-local\n```\n\n**Terminal 2** - Invoke the agent:\n```bash\nmake invoke-agent-local\n```\n\nThe agent runs on `http://localhost:8080` with reload. Logs appear in Terminal 1.\n\n## Triggering the Agent (AWS)\n\n**Scheduled**: Runs daily at 6am UTC (configured in EventBridge)\n\n**Manual**: Trigger anytime:\n\n```bash\nmake trigger-workflow\n```\n\n**Custom trigger**:\n\n```bash\naws events put-events --entries '[{\n  \"Source\": \"manual-trigger\",\n  \"DetailType\": \"execute-agent\",\n  \"Detail\": \"{}\"\n}]'\n```\n\n## Monitoring\n\nCheck 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.\n\n## Testing\n\nRun tests:\n\n```bash\nmake test                # All tests\nmake check               # Linting and formatting\n```\n\n## Cleanup\n\nRemove AWS resources:\n\n```bash\nmake cdk-destroy\n```\n\nRemove local artifacts:\n\n```bash\nmake clean\n```\n\n## Common Issues\n\n**Agent fails to start**: Check AWS credentials are configured and have necessary permissions (AWS Lambda, Amazon CloudWatch, Amazon S3, Amazon DynamoDB, Amazon Bedrock).\n\n**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.\n\n**Deployment fails**: Run `make cdk-bootstrap` first if this is your first CDK deployment in the account/region.\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for security issue reporting.\n\n## License\n\nThis library is licensed under the MIT-0 License. See the LICENSE file.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faws-samples%2Fsample-agentic-cost-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faws-samples%2Fsample-agentic-cost-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faws-samples%2Fsample-agentic-cost-optimizer/lists"}