Skip to content

Conversation

@pahud
Copy link
Contributor

@pahud pahud commented Feb 3, 2026

Issue # (if applicable)

Closes #36826.

Reason for this change

The gateway.addLambdaTarget() method fails with "Gateway execution role lacks permission to invoke Lambda function" due to IAM eventual consistency. The BedrockAgentCore service recently added a dry run Lambda invocation during CreateGatewayTarget API that executes before IAM has propagated the identity-based policy.

Solution Diagram

┌─────────────────────────────────────────────────────────────────────────────┐
│                        BEFORE (BROKEN)                                      │
└─────────────────────────────────────────────────────────────────────────────┘

    IAM Policy (identity-based)     GatewayTarget Creation     Dry Run Check
           │                               │                        │
           ▼                               ▼                        ▼
    ┌─────────────┐                 ┌─────────────┐          ┌─────────────┐
    │ IAM Service │                 │ CFN Creates │          │ Lambda      │
    │ (eventual   │                 │ Target      │─────────▶│ Invoke      │
    │ consistency)│                 │             │          │ Check ❌    │
    └─────────────┘                 └─────────────┘          └─────────────┘
           │                                                        │
           │  ⏱️ Policy still propagating...                        │
           └────────────────────────────────────────────────────────┘
                                                    ERROR: "lacks permission"

┌─────────────────────────────────────────────────────────────────────────────┐
│                        AFTER (FIXED)                                        │
└─────────────────────────────────────────────────────────────────────────────┘

    Lambda::Permission              GatewayTarget Creation     Dry Run Check
    (resource-based)                (DependsOn Permission)
           │                               │                        │
           ▼                               ▼                        ▼
    ┌─────────────┐                 ┌─────────────┐          ┌─────────────┐
    │ Lambda      │                 │ CFN Creates │          │ Lambda      │
    │ Service     │─────────────────│ Target      │─────────▶│ Invoke      │
    │ (sync ✅)   │  Permission     │ (after perm)│          │ Check ✅    │
    └─────────────┘  EXISTS         └─────────────┘          └─────────────┘

Description of changes

Added resource-based Lambda permission to bypass IAM eventual consistency issues:

  • target-configuration.ts: Added CfnPermission creation in LambdaTargetConfiguration.bind() with bedrock-agentcore.amazonaws.com service principal
  • target.ts: Added node.addDependency() on the permission in GatewayTarget constructor to ensure CloudFormation creates the permission before the target
  • gateway.test.ts: Added 7 new unit tests to verify permission creation and dependency ordering

This fix follows the established pattern from @aws-cdk/aws-bedrock-alpha (agent.ts) which uses the same approach for Bedrock agent Lambda permissions.

Describe any new or updated permissions being added

  • IAM permissions: No new IAM permissions required
  • Resource access: Adds AWS::Lambda::Permission resource-based policy allowing bedrock-agentcore.amazonaws.com to invoke the Lambda function with sourceArn scoped to the specific gateway

Description of how you validated changes

  • Unit tests: Added 7 new tests verifying:
    • AWS::Lambda::Permission resource is created for Lambda targets
    • Permission has correct principal (bedrock-agentcore.amazonaws.com) and sourceArn
    • GatewayTarget has DependsOn on the permission
    • Non-Lambda targets (OpenAPI, Smithy, MCP Server) do NOT create Lambda permission
    • Multiple Lambda targets create separate permissions
    • addLambdaTarget() method creates permission correctly
  • Integration tests: Existing integration test (integ.target.ts) validates end-to-end deployment

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…al consistency issue

The BedrockAgentCore service added a dry run Lambda invocation during
CreateGatewayTarget API that executes before IAM has propagated the
identity-based policy, causing deployments to fail.

This fix adds a resource-based Lambda permission with the
bedrock-agentcore.amazonaws.com service principal, which Lambda validates
synchronously (bypassing IAM eventual consistency). The GatewayTarget
now depends on this permission to ensure correct CloudFormation ordering.

Closes aws#36826
@aws-cdk-automation aws-cdk-automation requested a review from a team February 3, 2026 20:01
@github-actions github-actions bot added bug This issue is a bug. p2 labels Feb 3, 2026
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Feb 3, 2026
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results168 ran168 passed
TestResult
No test annotations available

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates168 ran168 passed
TestResult
No test annotations available

@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue is a bug. contribution/core This is a PR that came from AWS. p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants