Skip to content

(aws-events): ApiDestination missing fromArn methods for existing API destinations #29942

@keenangraham

Description

@keenangraham

Describe the bug

ApiDestination doesn't have any way to reference an existing EventBridge API destination:

export class ApiDestination extends Resource implements IApiDestination {
/**
* The Connection to associate with Api Destination
*/
public readonly connection: IConnection;
/**
* The Name of the Api Destination created.
* @attribute
*/
public readonly apiDestinationName: string;
/**
* The ARN of the Api Destination created.
* @attribute
*/
public readonly apiDestinationArn: string;
constructor(scope: Construct, id: string, props: ApiDestinationProps) {
super(scope, id, {
physicalName: props.apiDestinationName,
});
this.connection = props.connection;
let apiDestination = new CfnApiDestination(this, 'ApiDestination', {
connectionArn: this.connection.connectionArn,
description: props.description,
httpMethod: props.httpMethod ?? HttpMethod.POST,
invocationEndpoint: props.endpoint,
invocationRateLimitPerSecond: props.rateLimitPerSecond,
name: this.physicalName,
});
this.apiDestinationName = this.getResourceNameAttribute(apiDestination.ref);
this.apiDestinationArn = apiDestination.attrArn;
}
}

This is problematic because the aws-events-targets.ApiDestination expects an aws-events.ApiDestination:

private readonly apiDestination: events.IApiDestination,

I would like to have multiple Rules targeting the same (existing) ApiDestination. In my case the API destination is a Slack webhook with a secret in the URL endpoint.

Expected Behavior

To be able to reference an existing API destination by an ARN, like in Connection:

public static fromEventBusArn(scope: Construct, id: string, connectionArn: string, connectionSecretArn: string): IConnection {

Or Eventbus:

public static fromEventBusArn(scope: Construct, id: string, eventBusArn: string): IEventBus {

Current Behavior

No method to reference existing EventBridge API destination by ARN.

Reproduction Steps

Try to import existing API destination.

Possible Solution

Add ImportedApiConnection and method.

Additional Information/Context

No response

CDK CLI Version

2.138.0

Framework Version

No response

Node.js Version

20

OS

Sonoma

Language

Python

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eventsRelated to CloudWatch EventsbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions