This directory contains the AWS CDK infrastructure code for deploying the Fullstack AgentCore Solution Template.
- Node.js 18+
- AWS CLI configured with appropriate credentials
- AWS CDK CLI installed:
npm install -g aws-cdk
The file minimal-deploy-policy.json contains the minimum IAM permissions required to deploy this CDK application. This policy includes 30 actions across 7 statements covering CloudFormation, S3, SSM, ECR, IAM PassRole, and Amplify.
Important: This policy assumes CDK bootstrap has already been run in the target account. It does not include permissions for cdk bootstrap. To bootstrap a fresh account, you'll need additional IAM permissions (CreateRole, AttachRolePolicy, PutRolePolicy, etc.) - refer to the AWS CDK Bootstrap documentation for details.
Security Note: Some wildcards are present for resources (e.g., arn:aws:cloudformation:*:*:stack/*). For production environments, replace these with your specific resource ARNs to further scope down permissions.
All of the following commands assuming you are in the top of the infra-cdk/ directory
npm installnpm run buildnpx cdk bootstrapnpx cdk deploy --allnpm run build- Compile TypeScript to JavaScriptnpm run watch- Watch for changes and compile automaticallynpm run test- Run Jest unit testsnpx cdk deploy --all- Deploy all stacks to your AWS account/regionnpx cdk diff- Compare deployed stack with current statenpx cdk synth- Emit the synthesized CloudFormation templatenpx cdk destroy --all- Remove all deployed resources
Edit config.yaml to customize your deployment:
stack_name_base: "fullstack-agentcore-solution-template"
frontend:
domain_name: null # Optional: Set to your custom domain
certificate_arn: null # Optional: Set to your ACM certificate ARN
backend:
pattern: "strands-single-agent" # Available patterns: strands-single-agentinfra-cdk/
├── bin/
│ └── fast-cdk.ts # CDK app entry point
├── lib/
│ ├── fast-cdk-stack.ts # Main orchestrator stack
│ ├── backend-stack.ts # Backend/AgentCore stack
│ ├── frontend-stack.ts # Frontend/CloudFront stack
│ └── utils/ # Utility functions and constructs
├── test/
│ └── fast-cdk.test.ts # Unit tests
├── cdk.json # CDK configuration
├── config.yaml # Application configuration
├── package.json
└── tsconfig.json
- Make changes to TypeScript files in
lib/ - Run
npm run buildto compile - Run
npx cdk diffto see what will change - Run
npx cdk deploy --allto deploy changes
For faster iteration, use watch mode:
npm run watchThe CDK deployment creates multiple stacks with a specific deployment order:
-
Cognito Stack (CognitoStack):
- Cognito User Pool for user authentication
- User Pool Client for frontend OAuth flows
- User Pool Domain for hosted UI
-
Backend Stack (BackendStack):
- Machine Client & Resource Server: OAuth2 client credentials for service-to-service auth
- AgentCore Gateway: API gateway for tool integration with Lambda targets
- AgentCore Runtime: Bedrock AgentCore runtime for agent execution
- Supporting Resources: IAM roles, DynamoDB tables, API Gateway for feedback
-
Amplify Hosting Stack (AmplifyHostingStack):
- Amplify app for frontend hosting
- Branch configuration for deployments
- Custom domain setup (if configured)
Within the Backend Stack, components are created in this order:
- Cognito Integration: Import user pool from Cognito stack
- Machine Client: Create OAuth2 client for M2M authentication
- Gateway: Create AgentCore Gateway (depends on machine client)
- Runtime: Create AgentCore Runtime (independent of gateway)
This order ensures authentication components are available before services that depend on them, while keeping the runtime deployment separate since it doesn't directly depend on the gateway.
The agent container builds use a specific configuration to handle the repository structure efficiently:
Problem: Agent patterns need access to the shared gateway/ utilities package, but Docker build contexts cannot access parent directories using ../ paths.
Solution: Use repository root as build context with optimized file filtering:
- Build Context: Repository root (
/path/to/fullstack-agentcore-solution-template/) - Dockerfile Location:
patterns/{pattern}/Dockerfile - Package Installation: Install FAST package (
gateway/+pyproject.toml) as proper Python package - File Filtering:
.dockerignoreexcludes large directories to prevent build hangs
Issue: Large build contexts (including node_modules/, .git/, etc.) cause Docker builds to hang during the "transferring context" phase, especially in CDK deployments.
Solution: .dockerignore file at repository root excludes:
node_modules/directories (frontend and infra).git/version control data- Build artifacts (
cdk.out/,.next/,dist/) - Cache directories (
.ruff_cache/,__pycache__/)
Result: Build context reduced from ~100MB+ to ~10MB, eliminating hang issues.
Instead of copying files with relative paths, the Dockerfile:
-
Installs FAST package:
RUN pip install --no-cache-dir -e .- Makes
gatewayutilities available asfrom gateway.utils.* - Eliminates need for file copying between directories
- Works consistently across all agent patterns
- Makes
-
Copies only agent code:
COPY patterns/strands-single-agent/basic_agent.py .- Minimal file copying for the specific agent
- Clean separation between shared utilities and agent logic
-
Removes problematic requirements: Cleaned
requirements.txtto avoid duplicate FAST installation
This approach scales to multiple agent patterns without code duplication while maintaining clean Docker builds.
-
Backend Stack:
- Cognito User Pool integration and machine client
- AgentCore Gateway with Lambda tool targets
- AgentCore Runtime for agent execution
- ECR repository for agent container images
- CodeBuild project for container builds
- DynamoDB table for application data
- API Gateway for feedback endpoints
- IAM roles and policies
-
Amplify Hosting Stack:
- Amplify app for frontend deployment
- Automatic builds from Git branches
- Custom domain and SSL certificate integration
- Environment-specific deployments
If you encounter TypeScript compilation errors:
npm run buildCheck CloudFormation events in the AWS Console for detailed error messages.
If you need to start fresh:
rm -rf node_modules cdk.out
npm install
npm run buildRun unit tests:
npm test