Skip to content

(@aws-cdk/aws-bedrock-agentcore-alpha): addLambdaTarget() fails due to IAM eventual consistency #36826

@adam-weber

Description

@adam-weber

Describe the bug

gateway.addLambdaTarget() fails with "Gateway execution role lacks permission to invoke Lambda function" even though the IAM policy is correctly created with proper DependsOn ordering.

The BedrockAgentCore service recently added a dry run Lambda invocation during CreateGatewayTarget API. This dry run executes before IAM has propagated the identity-based policy (IAM eventual consistency).

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

2.233.0-alpha.0

Expected Behavior

addLambdaTarget() should successfully create the gateway target with Lambda permissions.

Current Behavior

Resource handler returned message:

"Gateway execution role lacks permission to invoke Lambda function arn:aws:lambda:us-west-2:XXXX:function:XXXX. Update the permission and retry"

Reproduction Steps

const gateway = new agentcore.Gateway(this, "Gateway", {
  gatewayName: "my-gateway",
  protocolConfiguration: new agentcore.McpProtocolConfiguration({
    supportedVersions: [agentcore.MCPProtocolVersion.MCP_2025_03_26],
  }),
  authorizerConfiguration: agentcore.GatewayAuthorizer.usingCustomJwt({
    discoveryUrl: cognitoDiscoveryUrl,
    allowedClients: [clientId],
  }),
});

const toolLambda = new lambda.Function(this, "ToolLambda", { /* ... */ });

// This fails
gateway.addLambdaTarget("Target", {
  gatewayTargetName: "my-target",
  lambdaFunction: toolLambda,
  toolSchema: agentcore.ToolSchema.fromInline(toolSpec),
});

Possible Solution

LambdaTargetConfiguration.bind() should add a resource-based policy in addition to grantInvoke():

this.lambdaFunction.addPermission('GatewayInvoke', {
  principal: new ServicePrincipal('bedrock-agentcore.amazonaws.com'),
  sourceArn: gateway.gatewayArn,
});

Resource-based policies are validated synchronously by Lambda, avoiding IAM eventual consistency issues.

Additional Information/Context

Confirmed with AgentCore engineering that they recently added dry run Lambda invocation validation to CreateGatewayTarget. The dry run hits IAM before the identity-based policy has propagated.

Workaround: Manually add AWS::Lambda::Permission with bedrock-agentcore.amazonaws.com as principal.

AWS CDK Library version (aws-cdk-lib)

2.233.0

AWS CDK CLI version

2.1029.3

Node.js Version

v23.11.0

OS

macOS

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions