Connect another system with an API
Add a target for each system you connect, such as an order or billing system. For Salesforce custom objects, use the stack's second target (see Example: add your own Salesforce operations), which reuses the stack's Salesforce token. First create the API credentials in the system, then add the credentials and the target to the gateway. The following table compares the target types for a REST API.
| Target | Use it for | What to know |
|---|---|---|
Built-in template |
Contact center data in a system the gateway has a built-in template for, such as Salesforce. |
Added in the gateway console only, with a fixed set of operations. The
built-in Salesforce template's query operation runs any SOQL query as the integration
user. The CloudFormation template's |
OpenAPI target |
Domain data, writes a template doesn't offer, and systems without a template. |
You describe the operations in an OpenAPI document. Added in the console, with the AWS CLI, or in a CloudFormation template. |
AWS Lambda target |
An operation that needs logic, such as combining two calls. |
You write and maintain the function. |
The built-in Salesforce template (Salesforce Lightning Platform) reaches Developer Edition orgs only
(develop.my.salesforce.com); for a production or sandbox org, use the
CloudFormation template, or an OpenAPI target whose server is your My Domain URL. See Built-in templates from integration providers as targets.
If you write an OpenAPI document, for domain data or a system without a template, the gateway needs the following:
OpenAPI 3.0 or 3.1, not Swagger 2.0.
An
operationIdon every operation. It becomes the tool's name.A fixed server URL in
servers.No
securitySchemes. The gateway adds authentication from the credential provider.Simple parameters, with no
oneOf,anyOforallOf.
Paste the document inline, or store it as an Amazon S3 object. See OpenAPI schema targets in the Amazon Bedrock AgentCore Developer Guide.
If your API is on a private network, such as in a VPC or on premises, the gateway doesn't call private IP addresses directly. Add the OpenAPI or MCP server target with a private endpoint; an identity provider inside your network also needs a private endpoint on the OAuth client. See Connect to private resources in your VPC using VPC Lattice.
A Lambda target calls your function with the gateway's IAM service role; it doesn't use an OAuth client or API key. See Add targets to an existing AgentCore gateway.
Create the API credentials in the system
Create an integration user, and OAuth client credentials or an API key,
whichever your API accepts. If the API publishes an OpenID Connect discovery document, note its URL; the gateway uses it to find the token endpoint. If it doesn't, note its issuer and token endpoint instead, for the OAuth client's Manual config option. For an API key, note whether the API expects it in a header or a query parameter, and any prefix, such as Bearer.
Add the system to the gateway
For each system, add its OAuth client or API key, and then a target that uses it. A stack delete fails until you delete what you added; see Remove the integration. Use a current version of the AWS CLI.
To add the OAuth client or API key
-
Open the AgentCore Identity console
. In Outbound Auth, choose Add OAuth client / API key. -
For OAuth, choose Add OAuth client, choose Custom provider, and under Provider configurations choose Discovery URL. For Salesforce, the discovery URL is your My Domain URL followed by
/.well-known/openid-configuration. If the API has no discovery document, choose Manual config and enter its issuer and token endpoint. Enter the client ID and the client secret, or choose Provide Client secret via Secrets Manager to reference a secret you rotate there. Choose Add OAuth Client. -
For an API key, choose Add API key, enter a name and the key, and save it.
Or expand this block, copy it, and paste it at the prompt. It asks for the Region, the type, a name and the values, builds the input in a file that only you can read, so the secret never appears on screen or on the command line, and prints the new OAuth client's or API key's ARN:
( umask 077; D=$(mktemp -d); trap 'rm -rf "$D"' EXIT R=${AWS_REGION:-us-east-1} printf 'Region of the gateway [%s]: ' "$R"; read -r REGION; REGION=${REGION:-$R} printf 'Credential type, oauth or apikey [oauth]: '; read -r KIND; KIND=${KIND:-oauth} printf 'Name for the OAuth client or API key [my-system-%s]: ' "$KIND"; read -r NAME; NAME=${NAME:-my-system-$KIND} if [ "$KIND" = oauth ]; then printf "Discovery URL (the system's /.well-known/openid-configuration URL): "; read -r DISCOVERY printf 'Client ID: '; read -r CLIENT_ID printf 'Client secret (input hidden: paste and press Enter): ' else printf 'API key (input hidden: paste and press Enter): ' fi read -rs SYSTEM_SECRET; echo printf '%s' "$SYSTEM_SECRET" > "$D/secret"; unset SYSTEM_SECRET [ -s "$D/secret" ] || { echo "No secret entered; nothing was created."; exit 1; } python3 -I - "$D" "$KIND" "$NAME" "${DISCOVERY:-}" "${CLIENT_ID:-}" <<'PY' || exit 1 import json, sys d, kind, name, discovery, client_id = sys.argv[1:] secret = open(d + "/secret").read().strip() if kind == "oauth": value = {"name": name, "credentialProviderVendor": "CustomOauth2", "oauth2ProviderConfigInput": { "customOauth2ProviderConfig": {"oauthDiscovery": {"discoveryUrl": discovery}, "clientId": client_id, "clientSecret": secret}}} else: value = {"name": name, "apiKey": secret} json.dump(value, open(d + "/input.json", "w")) PY if [ "$KIND" = oauth ]; then aws bedrock-agentcore-control create-oauth2-credential-provider --region "$REGION" \ --cli-input-json "file://$D/input.json" --query credentialProviderArn --output text else aws bedrock-agentcore-control create-api-key-credential-provider --region "$REGION" \ --cli-input-json "file://$D/input.json" --query credentialProviderArn --output text fi )
To add the target
-
In the AgentCore console, open the stack's gateway (the stack's
GatewayIdoutput), choose the Targets tab, and add an OpenAPI, AWS Lambda or MCP server target that uses the OAuth client or API key you added. Note the target name: a guide flow calls tools asgateway_.gateway-id__target-name___operation
To add an OpenAPI target that uses an OAuth client with the AWS CLI instead,
save the system's OpenAPI document as a file in the current folder, and expand this block, copy it, and paste it at the prompt. It asks for the Region, the stack name, the target
name, the file and the OAuth client's ARN, waits up to five minutes while the
target is created, and prints its status, which is READY when the
target is ready; any other status names the problem, such as
FAILED:
( R=${AWS_REGION:-us-east-1} printf 'Region of the stack [%s]: ' "$R"; read -r REGION; REGION=${REGION:-$R} printf 'Stack name [connect-sf-real-time]: '; read -r STACK; STACK=${STACK:-connect-sf-real-time} aws cloudformation describe-stacks --region "$REGION" --stack-name "$STACK" --query 'Stacks[0].StackStatus' --output text > /dev/null \ || { echo "No stack named $STACK in $REGION. Check the stack name and the Region."; exit 1; } G=$(aws cloudformation describe-stacks --region "$REGION" --stack-name "$STACK" \ --query "Stacks[0].Outputs[?OutputKey=='GatewayId'].OutputValue | [0]" --output text) || exit 1 printf 'Target name [my-system]: '; read -r NAME; NAME=${NAME:-my-system} printf 'OpenAPI file [my-system-openapi.json]: '; read -r FILE; FILE=${FILE:-my-system-openapi.json} printf 'OAuth client ARN, from the credential step: '; read -r PROVIDER D=$(mktemp -d); trap 'rm -rf "$D"' EXIT python3 -I - "$FILE" "$PROVIDER" "$D" <<'PY' || exit 1 import json, sys schema, provider, d = sys.argv[1:] json.dump({"mcp": {"openApiSchema": {"inlinePayload": open(schema).read()}}}, open(d + "/target.json", "w")) json.dump([{"credentialProviderType": "OAUTH", "credentialProvider": {"oauthCredentialProvider": { "providerArn": provider, "scopes": [], "grantType": "CLIENT_CREDENTIALS"}}}], open(d + "/credentials.json", "w")) PY T=$(aws bedrock-agentcore-control create-gateway-target --region "$REGION" --gateway-identifier "$G" --name "$NAME" \ --target-configuration "file://$D/target.json" --credential-provider-configurations "file://$D/credentials.json" \ --query targetId --output text) || exit 1 for i in $(seq 30); do S=$(aws bedrock-agentcore-control get-gateway-target --region "$REGION" --gateway-identifier "$G" --target-id "$T" \ --query status --output text) || exit 1 case "$S" in CREATING|UPDATING|SYNCHRONIZING) sleep 10 ;; *) break ;; esac done echo "Target $NAME ($T): $S" )
For an MCP server target, add it in the console.
Write the full host into the server URL of every target you add, or limit a
variable host with an enum of the hosts you allow. A server URL
with a variable host and no enum, such as the built-in Salesforce
template's {domainName}, lets whoever sets that value send the
integration user's access token to another host.
For an API key, the credential configuration names the API key credential provider instead of the OAuth client. In credentialProviderConfigurations, set credentialProviderType to API_KEY, and in credentialProvider, apiKeyCredentialProvider with the provider's providerArn and, if the API expects it somewhere other than the default, credentialLocation, credentialParameterName and credentialPrefix. Wait for the target's status to be READY.