Skip to content

feat(events): add grantInvokeApiDestination to ApiDestination - #38590

Open
lemon0333 wants to merge 2 commits into
aws:mainfrom
lemon0333:feat/api-destination-grant-invoke
Open

feat(events): add grantInvokeApiDestination to ApiDestination#38590
lemon0333 wants to merge 2 commits into
aws:mainfrom
lemon0333:feat/api-destination-grant-invoke

Conversation

@lemon0333

Copy link
Copy Markdown

Issue # (if applicable)

Closes #30386.

Reason for this change

IApiDestination / ApiDestination in aws-events had no way to grant a
principal permission to invoke the destination. Users who want to let a
role invoke an EventBridge API destination (for example a
scheduler.amazonaws.com role used by an EventBridge Scheduler target)
had to construct the events:InvokeApiDestination policy statement and the
correct resource ARN by hand.

The L1 resource already exposes an ArnForPolicy attribute (surfaced on
the L2 as apiDestinationArnForPolicy) which is the ARN format expected in
the Resource element of an IAM policy statement for an API destination,
so a first-class grant helper is a natural addition.

Description of changes

  • Add grantInvokeApiDestination(grantee: iam.IGrantable): iam.Grant to the
    IApiDestination interface and implement it, granting the
    events:InvokeApiDestination action.
  • The grant is scoped to apiDestinationArnForPolicy (the resource-format
    ARN) when it is available, and falls back to apiDestinationArn for
    imported destinations that do not provide it.
  • Introduce a shared ApiDestinationBase abstract class (mirroring the
    existing EventBusBase pattern in the same module) so the grant method and
    the apiDestinationRef getter are shared by both created (ApiDestination)
    and imported (fromApiDestinationAttributes) destinations. The two
    previously-duplicated apiDestinationRef getters are consolidated into the
    base class.

The maintainer greenlit this addition on the issue.

Describe any new or updated permissions being added

events:InvokeApiDestination — added to the grantee's identity policy by
grantInvokeApiDestination, scoped to the API destination's resource-format
ARN (ArnForPolicy), falling back to the destination ARN for imported
destinations.

Description of how you validated changes

  • Added unit tests in aws-events/test/api-destination.test.ts asserting the
    synthesized AWS::IAM::Policy for: a created destination (uses the
    ArnForPolicy Fn::GetAtt), an imported destination with ArnForPolicy,
    and an imported destination without ArnForPolicy (falls back to the plain
    ARN). All aws-events/test/api-destination tests pass (6/6).
  • Updated the integ.api-destination integration test to grant a role invoke
    permission and regenerated its snapshot. The snapshot now includes the
    events:InvokeApiDestination statement scoped to the destination's
    ArnForPolicy.

Checklist


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

Add a `grantInvokeApiDestination(grantee)` method to `IApiDestination`
and `ApiDestination` that grants the `events:InvokeApiDestination`
action on the API destination's ARN.

The grant is scoped to `apiDestinationArnForPolicy` (the ARN in resource
format) when available, since that is the ARN format expected in the
Resource element of an IAM policy statement for an API destination, and
falls back to `apiDestinationArn` for imported destinations that do not
provide it.

A shared `ApiDestinationBase` abstract class now hosts the grant method
and the `apiDestinationRef` getter so it is available on both created and
imported destinations, mirroring the existing `EventBusBase` pattern.

Closes aws#30386.
@lemon0333
lemon0333 deployed to automation August 18, 2026 07:15 — with GitHub Actions Active
@lemon0333
lemon0333 deployed to automation August 18, 2026 07:15 — with GitHub Actions Active
@github-actions github-actions Bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Aug 18, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 18, 2026 07:15
@lemon0333
lemon0333 deployed to automation August 18, 2026 07:15 — with GitHub Actions Active

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(This review is outdated)

The PR linter requires feature PRs to touch a README. Add an
API Destinations section showing grantInvokeApiDestination usage.
@lemon0333
lemon0333 deployed to automation August 18, 2026 07:22 — with GitHub Actions Active
@lemon0333
lemon0333 deployed to automation August 18, 2026 07:23 — with GitHub Actions Active
@aws-cdk-automation
aws-cdk-automation dismissed their stale review August 18, 2026 07:24

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@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 Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. 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-events): IApiDestination is missing grantInvokeApiDestination

2 participants