Deterministic procedure for creating an AgentCore Gateway target that converts
REST APIs into MCP tools agents can use. Gateway supports three authentication
types, each with a different setup workflow. The creation order is strict —
credentials MUST be created before the gateway target.
You MUST create the credential provider BEFORE creating the gateway target — this ordering is mandatory
Creating a target without credentials results in a “credential provider not found” error
For API key authentication:
You MUST NOT pass the API key as a literal value on the command line — shell history exposes it
You MUST ask the user to set the key as an environment variable: export API_KEY=<their-key>
Create the credential provider: aws bedrock-agentcore-control create-api-key-credential-provider --name <name> --api-key "$API_KEY" — the service encrypts and stores the key in Secrets Manager internally (response includes apiKeySecretArn). Do NOT manually create a Secrets Manager secret; the service manages this.
For key rotation: aws bedrock-agentcore-control update-api-key-credential-provider --name <name> --api-key "$NEW_API_KEY" — do NOT call secretsmanager rotate-secret directly on the service-managed secret
For OAuth authentication:
The client secret is passed via the create-oauth2-credential-provider API call — the service encrypts and stores it in Secrets Manager automatically (response includes clientSecretArn). Do NOT manually create a Secrets Manager secret.
You MUST NOT hardcode client secrets in agent code or configuration
Configure token endpoint, client ID, client secret, and scopes
Refer to the latest AWS documentation on AgentCore Gateway OAuth configuration options
For Lambda/IAM authentication:
No credential provider needed — skip to Step 3
The Gateway uses IAM role-based authentication to invoke the Lambda
The Lambda MUST have a resource-based policy allowing the Gateway service role to invoke it, with aws:SourceAccount and aws:SourceArn conditions to prevent confused deputy. Refer to the latest AWS documentation on AgentCore Gateway permissions for current policy patterns.
You MUST link the OpenAPI schema S3 URI from Step 1
If using API key or OAuth: You MUST link the credential provider ARN from Step 2
If using Lambda: You MUST specify the Lambda ARN and configure IAM role with lambda:InvokeFunction scoped to the specific Lambda ARN — avoid Resource: "*"
You MUST NOT create the target before the credential provider exists (for API key/OAuth)
Encryption: S3 encrypts objects at rest by default (SSE-S3). For sensitive schemas, use SSE-KMS with a customer managed key. Target endpoints MUST use HTTPS — Gateway rejects HTTP endpoints.
Least privilege: Scope IAM roles to specific resource ARNs — the Gateway service role should only access the specific S3 bucket, Secrets Manager secret, and Lambda function needed. Avoid Resource: "*".
Sensitive data in logs: API keys and OAuth tokens may appear in CloudTrail logs. Enable CloudTrail log encryption with KMS. Do NOT log credential values in agent output.
Monitoring: Enable CloudWatch alarms for gateway target errors (5xx rates, latency). Enable CloudTrail for audit logging of all bedrock-agentcore-control API calls.
TLS: All target endpoints must use TLS 1.2+. Use ACM certificates for custom domains.
Refer to the latest AWS documentation on Bedrock security best practices.