Deploy E‑commerce Agents to Production with Just a Few Lines of Code Using AgentCore Runtime
The article shows how to combine Claude Agent SDK, Amazon Bedrock, and AgentCore Runtime to move a locally‑developed agent into a stable, observable, and scalable production environment, covering architecture, CRIS choices, code examples, packaging, deployment steps, IAM setup, and best‑practice insights.
In many Agent development projects, code runs smoothly locally but encounters engineering‑level uncertainties—such as insufficient execution time, unstable session state, resource allocation issues, inconsistent model access, and lack of observability—once deployed to production. These problems stem from differences between the local runtime and the production model system rather than bugs in the Agent logic itself.
By pairing Claude Agent SDK with Amazon Bedrock’s managed model services and wrapping the application with AgentCore Runtime, developers can retain the rapid iteration experience of local development while satisfying production requirements for stability, isolation, and observability with minimal code changes.
AgentCore Runtime
AgentCore Runtime is a serverless execution environment built on microVM isolation. Each invocation runs in an independent microVM, guaranteeing complete isolation between users, tasks, and Agents. A single call can run up to eight hours, making it suitable for long‑running reasoning, analysis, or external tool calls. The runtime is framework‑agnostic: any of Strands Agents, Claude Agent SDK, LangGraph, CrewAI, or custom frameworks can be executed by providing a compliant entry script.
The SDK currently supports Python and TypeScript, allowing Agents to run without developers managing underlying infrastructure.
Claude Agent SDK
Claude Agent SDK is a development engine and modular infrastructure that goes beyond simple prompt wrappers or low‑code platforms. It offers context management (memory/session), tool invocation, task execution, permission and security handling, and state management, enabling developers to build production‑ready, autonomous Agents.
It supports use cases requiring long context, complex interactions, multiple tool calls, strict security, or high‑availability deployment, such as code generation, document analysis, automated workflows, report generation, and RAG for long documents.
Amazon Bedrock Model Service
Bedrock provides a fully managed generative‑AI service that unifies access to leading models (e.g., Amazon Nova, Claude, DeepSeek) with built‑in enterprise‑grade security, governance, and scaling. Using Bedrock, Agents can call models without provisioning infrastructure, and developers can switch or combine models (e.g., global.anthropic.claude‑sonnet‑4‑5) to optimise cost and performance.
Global CRIS vs. GEO CRIS
Global CRIS (e.g., global.anthropic.claude‑sonnet‑4‑5‑20250929‑v1:0) lets the same model be invoked from any AWS region, simplifying global deployment and providing cross‑region resiliency. GEO CRIS restricts model execution to a specific geographic boundary, satisfying data‑residency or compliance requirements. The article demonstrates the Global CRIS path.
Architecture Overview
┌─────────────────────────────────────┐
│ User Request │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ AgentCore Runtime │
│ (managed infra, auto‑scale, monitor) │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ BedrockAgentCoreApp instance │
│ • Receive HTTP/MCP request │
│ • Manage session state │
│ • Handle short‑term memory (STM) │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ main entrypoint │
│ @app.entrypoint async function │
│ • Parse payload │
│ • Dispatch example functions │
│ • Handle errors & return results │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ Function scheduling │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ Claude Agent SDK query function │
│ • Build Claude request │
│ • Process async message stream │
│ • Manage tool calls & results │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ Claude Agent SDK processing layer │
│ • AssistantMessage, ResultMessage, │
│ ToolMessage handling │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ Bedrock Claude model │
│ (Sonnet 4.5 inference, Global CRIS) │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ Tool execution layer │
│ • Read / Write / custom tools │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ Response handling │
│ • Extract TextBlock, format output │
│ • Compute & display cost │
└─────────────────────┬───────────────┘
▼
┌─────────────────────────────────────┐
│ Final HTTP/MCP response │
└─────────────────────────────────────┘Local Development Example
A minimal Python script ( claude_agent_sdk_on_local_machine.py) demonstrates three scenarios: basic Q&A, system‑prompt role setting, and tool usage (file read/write). Running the script prints the Claude response and the incurred cost.
#!/usr/bin/env python3
import anyio
from claude_agent_sdk import (
AssistantMessage,
ClaudeAgentOptions,
ResultMessage,
TextBlock,
query,
)
async def demo_basic_query():
print("✨ 【Example 1: Basic Q&A】")
async for message in query(prompt="If a=8 and b=15, what is c?"):
if isinstance(message, AssistantMessage):
for block in message.content:
if isinstance(block, TextBlock):
print(f"✨ Assistant: {block.text}")
# ... (demo_system_prompt and demo_tool_usage omitted for brevity) ...
async def main():
await demo_basic_query()
await demo_system_prompt()
await demo_tool_usage()
if __name__ == "__main__":
anyio.run(main)Packaging for AgentCore Runtime
To run the same Agent in AgentCore Runtime, only a few lines are added: import the bedrock_agentcore SDK, create a BedrockAgentCoreApp instance, and decorate the entry function with @app.entrypoint. The rest of the Agent code remains unchanged.
# claude_agent_sdk_on_agentcore_runtime.py
#!/usr/bin/env python3
import anyio
from bedrock_agentcore import BedrockAgentCoreApp
from claude_agent_sdk import (
AssistantMessage,
ClaudeAgentOptions,
ResultMessage,
TextBlock,
query,
)
app = BedrockAgentCoreApp()
async def demo_basic_query():
print("✨ 【Example 1: Basic Q&A】")
async for message in query(prompt="If a=8 and b=15, what is c?"):
if isinstance(message, AssistantMessage):
for block in message.content:
if isinstance(block, TextBlock):
print(f"✨ Assistant: {block.text}")
# ... (other demos unchanged) ...
@app.entrypoint
async def main(payload: dict = None):
await demo_basic_query()
await demo_system_prompt()
await demo_tool_usage()
if __name__ == "__main__":
app.run()Deployment Workflow
Install the AgentCore Starter Toolkit: pip install bedrock-agentcore-starter-toolkit Create requirements.txt with the needed SDK versions:
bedrock-agentcore==1.0.4
claude-agent-sdk==0.1.3Configure the Agent with the entry script:
agentcore configure -e claude_agent_sdk_on_agentcore_runtime.pyThe CLI prompts for agent name, dependency file, deployment type (container), execution role (auto‑create), ECR repository (auto‑create), and memory settings (short‑term enabled, long‑term disabled). It generates a Dockerfile and a .bedrock_agentcore.yaml configuration.
Modify the generated Dockerfile to install Node.js, the Claude Code CLI, and any additional packages. Example snippet:
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
WORKDIR /app
ENV UV_SYSTEM_PYTHON=1 \
UV_COMPILE_BYTECODE=1 \
UV_NO_PROGRESS=1 \
PYTHONUNBUFFERED=1 \
AWS_REGION=us-east-1
RUN apt-get update && apt-get install -y nodejs npm && rm -rf /var/lib/apt/lists/*
RUN npm install -g @anthropic-ai/claude-code
COPY requirements.txt .
RUN uv pip install -r requirements.txt
COPY . .
CMD ["opentelemetry-instrument", "python", "-m", "claude_agent_sdk_on_agentcore_runtime"]Launch the deployment, passing required environment variables (Bedrock token, model IDs, etc.):
agentcore launch -a claude_agent_sdk_on_agentcore_runtime \
--env CLAUDE_CODE_USE_BEDROCK=1 \
--env AWS_BEARER_TOKEN_BEDROCK=<your_token> \
--env DEBUG=true \
--env ANTHROPIC_MODEL=global.anthropic.claude-sonnet-4-5-20250929-v1:0 \
--env ANTHROPIC_SMALL_FAST_MODEL=global.anthropic.claude-haiku-4-5-20251001-v1:0After deployment, verify that the AgentCore Runtime, short‑term memory, ECR repository, and IAM roles/policies have been created. Test the endpoint with curl -X POST http://localhost:8080/invocations -d "{}" or via agentcore invoke '{}'.
Monitor execution logs in Amazon CloudWatch, using the “Logs” and “Live Tail” features to debug and observe request metrics.
Experience Summary
Unlike many serverless services that limit execution to a few minutes, AgentCore Runtime allows up to eight hours per invocation, enabling deep research, long‑running workflows, or large‑scale data processing without timeout concerns. The microVM isolation guarantees that concurrent user requests do not share state, eliminating memory leaks and interference.
Conclusion
The guide demonstrates that the gap between local development and production deployment can be narrowed to a handful of code modifications and a few CLI commands. By wrapping a Claude Agent SDK Agent with AgentCore Runtime, teams can keep their original code structure, avoid framework rewrites, and benefit from Amazon Bedrock’s unified, secure model‑calling platform, achieving controllable, observable, and scalable production‑grade Agent deployments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Amazon Cloud Developers
Official technical community of Amazon Cloud. Shares practical AI/ML, big data, database, modern app development, IoT content, offers comprehensive learning resources, hosts regular developer events, and continuously empowers developers.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
