For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Connect to AWS Bedrock AgentCore
Route requests to an Amazon Bedrock AgentCore agent runtime through agentgateway.
With agentgateway, you can route requests directly to an Amazon Bedrock AgentCore agent runtime with an aws.agentCore backend. You do not need a separate proxy, custom code, or the AWS SDK.
Important
Want to use agentgateway in a Kubernetes environment with the Gateway API? Check out the agentgateway on Kubernetes docs.
About AWS Bedrock AgentCore
Amazon Bedrock AgentCore is a runtime that hosts deployed agents, each with its own invocation endpoint. To reach an AgentCore runtime, you supply its Amazon Resource Name (ARN) to an aws.agentCore backend. Agentgateway derives every connection detail from that ARN, so you do not construct the endpoint or encode the ARN yourself.
For an ARN in the format arn:aws:bedrock-agentcore:<region>:<account-id>:runtime/<runtime-id>, agentgateway does the following:
- Connects to
bedrock-agentcore.<region>.amazonaws.comon port 443 over TLS, with the system trust store. - Replaces the request path with
/runtimes/<url-encoded-ARN>/invocations. - Signs the request with AWS Signature Version 4 (SigV4) under the
bedrock-agentcoresigning name, unless a backend authentication policy overrides the signing.
The ARN must carry bedrock-agentcore as its service element. Agentgateway rejects any other ARN when it loads the configuration.
Note
AgentCore identifies a runtime entirely by its ARN, and the request path is replaced in full. A subpath that a client appends to the route, such as /agentcore/my-agent, is dropped, and the request still reaches the ARN in the backend. To route to more than one runtime, create a separate backend and route for each one. To target a different version or endpoint of the same runtime, set qualifier.
Authentication
AgentCore runtimes support two authentication modes, which you choose when you deploy the runtime in AWS. Both modes work with an aws.agentCore backend.
backendAuth.aws policy. For the full set of AWS options, see AWS backend authentication.Before you begin
- Install the
agentgatewaybinary. - Deploy an Amazon Bedrock AgentCore agent runtime in your AWS account, and get its ARN. For steps to build and deploy a runtime, see the Amazon Bedrock AgentCore documentation.
- Get credentials for the runtime’s authentication mode.For IAM (SigV4), make AWS credentials that are allowed to invoke the runtime available to agentgateway. The credential chain reads environment variables,
~/.aws/configand~/.aws/credentials, a web identity token, container credentials, and IMDSv2, and it stops at the first source that returns credentials.
Step 1: Configure the AgentCore backend
Create a configuration file with a route to the AgentCore runtime. The aws.agentCore settings name the runtime that you want to invoke, and the configuration depends on the runtime’s authentication mode.
Create a configuration file with an
aws.agentCorebackend and no authentication policy. Agentgateway signs each request with SigV4 by using the credentials in its environment. Replace theagentRuntimeArnvalue with the ARN of your runtime.cat <<'EOF' > config.yaml # yaml-language-server: $schema=https://agentgateway.dev/schema/config gateways: default: port: 3000 routes: - matches: - path: pathPrefix: /agentcore backends: - aws: agentCore: agentRuntimeArn: arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/my-agent-runtime EOFStart agentgateway with the configuration file.
agentgateway -f config.yaml
| Setting | Description |
|---|---|
aws.agentCore.agentRuntimeArn | The ARN of the AgentCore agent runtime to invoke, in the format arn:aws:bedrock-agentcore:<region>:<account-id>:runtime/<runtime-id>. Agentgateway derives the endpoint, the signing region, and the invocation path from this value. |
aws.agentCore.qualifier | Optional. The runtime version or endpoint qualifier to invoke, which is sent as a qualifier query parameter. Omit this setting to use the runtime’s DEFAULT endpoint, as this example does. |
policies.backendAuth | Optional. Replaces the default SigV4 signing for the backend. Omit this setting to sign requests with the AWS credential chain. To authenticate to a runtime that uses a JWT authorizer, set backendAuth.key.value to the token, either as a file reference or as an inline string. The token goes in the Authorization header with a Bearer prefix, unless you set backendAuth.key.location. |
policies.requestHeaderModifier | Optional. Headers to set before the request is sent upstream, such as the X-Amzn-Bedrock-AgentCore-Runtime-User-Id header that AgentCore uses to associate requests with a user session. Omit this setting to send the request headers unchanged, as this example does. |
To reuse one AgentCore backend across several routes, move the backend to a top-level backends entry and reference it by name. The reference is namespace-qualified, so a backend in the default namespace needs a leading slash.
backends:
- name: agentcore
aws:
agentCore:
agentRuntimeArn: arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/my-agent-runtime
routes:
- matches:
- path:
pathPrefix: /agentcore
backends:
- backend: /agentcoreStep 2: Verify the connection
Send a request to the AgentCore runtime through agentgateway. The request body depends on the agent that you deployed to the runtime. The following example sends a simple prompt.
curl -X POST http://localhost:3000/agentcore \ -H "Content-Type: application/json" \ -d '{"prompt": "Hello from agentgateway!"}'Example output: The agent responds with its own payload format.
{"result": {"role": "assistant", "content": [{"text": "Hello! How can I help you today?"}]}}In the terminal where agentgateway runs, verify that the request log names the AgentCore endpoint for the runtime’s region.
info request gateway=default/default listener=default route=default/route0 endpoint=bedrock-agentcore.us-west-2.amazonaws.com:443 src.addr=[::1]:49215 http.method=POST http.host=localhost http.path=/agentcore http.version=HTTP/1.1 http.status=200 protocol=http duration=437msIf the request fails, use the response and the request log to tell an authentication problem from a routing problem. A log line that carries an
error=field andreason=UpstreamFailuremeans that agentgateway failed before it sent the request. A response that carries anx-amzn-requestidheader came from AWS.Response Cause 403withThe security token included in the request is invalidThe SigV4 credentials that agentgateway resolved are not valid. Check the credential source that the chain reached first. 403from a JWT authorizerThe token is expired, or it does not match the runtime’s Inbound Auth settings. Check the discovery URL, the allowed client ID, and that you sent an access token. 404withNo endpoint or agent found with qualifierThe ARN or the qualifiervalue does not name a deployed runtime endpoint. The message reports the qualifier that was used, which isDEFAULTwhen you omit the setting.500withbackend authentication failedagentgateway could not resolve credentials at all, so no request was signed. A failed assumeRolecall reports this way.
Clean up
You can remove the resources that you created in this guide.Stop agentgateway in the terminal where it runs.
Remove the configuration file and the token file.
rm -f config.yaml config-jwt.yaml agentcore-token.jwt