By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You've built an agent locally. Now you need to run it on AWS infrastructure so other applications can call it reliably. The path from Python file to production involves four concrete steps: writing the agent code, packaging it as a container, deploying to AgentCore Runtime, and invoking it from your client application.
Your agent code gets packaged into a Docker container, pushed to Amazon ECR, and then AgentCore Runtime spins it up in a microVM. Once deployed, your client app sends requests to that Runtime and gets responses back using a session ID to maintain context across invocations.
The BedrockAgentCoreApp class from the SDK handles the web server plumbing for you. You write your agent logic in a single function, mark it with @app.entrypoint, and the SDK converts it into an HTTP endpoint.
# agent.py
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from strands import Agent # any framework works; Strands is just an example
app = BedrockAgentCoreApp()
agent = Agent() # uses a default Bedrock model
@app.entrypoint
def invoke(payload):
user_message = payload.get("prompt", "Hello!")
result = agent(user_message)
return {"result": str(result)}
if __name__ == "__main__":
app.run() # serves on 0.0.0.0:8080
The entrypoint function receives a payload dictionary and must return a dictionary. The SDK wraps your return value and sends it back to the client. You can use any agent framework; Strands is shown here as an example.
The AgentCore CLI automates the heavy lifting. One command scaffolds your project structure, another builds the Docker image, pushes it to ECR, and creates the Runtime in one go. Check the official docs for the newest flags, as options may change.
agentcore create --name myagent # scaffold a project
agentcore deploy # build + push + create the runtime
agentcore invoke '{"prompt": "Hello!"}' # test it
Once deployed, you call the agent from your app using the Bedrock AgentCore client. Each conversation needs its own session ID so the Runtime can maintain state across multiple requests.
import json, uuid, boto3
client = boto3.client("bedrock-agentcore", region_name="us-west-2")
resp = client.invoke_agent_runtime(
agentRuntimeArn="arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/myagent-abc",
runtimeSessionId=str(uuid.uuid4()) + "-session", # one id per conversation
payload=json.dumps({"prompt": "What can you do?"}).encode(),
)
print(resp["response"].read().decode())
The runtimeSessionId should be unique per conversation. Pass your input as JSON in the payload parameter and decode the response stream to get the result.
AgentCore Runtime expects your container to meet a specific HTTP contract. It must listen on 0.0.0.0 port 8080, be built for ARM64 architecture, and expose a POST /invocations endpoint that receives requests and returns JSON or Server-Sent Events. A GET /ping endpoint provides health checks, and an optional WebSocket endpoint at /ws enables real-time two-way streaming.
You rarely write these endpoints by hand: BedrockAgentCoreApp implements /invocations and /ping for you. Knowing the contract just helps you debug.
If something goes wrong during deployment or invocation, understanding this contract helps you diagnose whether the issue is in your agent code, the container configuration, or how you're calling the Runtime.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.