Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
keenangraham opened this issue Apr 24, 2024 · 3 comments · Fixed by #29943, rwlxxvii/containers#124 or rwlxxvii/containers#140 · May be fixed by NOUIY/aws-solutions-constructs#99 or NOUIY/aws-solutions-constructs#101
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@keenangraham
Copy link

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

@keenangraham keenangraham added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 24, 2024
@github-actions github-actions bot added the @aws-cdk/aws-events Related to CloudWatch Events label Apr 24, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 24, 2024
@khushail
Copy link
Contributor

thanks @keenangraham for reporting this.

@khushail khushail added p2 effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Apr 24, 2024
@mergify mergify bot closed this as completed in #29943 Apr 25, 2024
mergify bot pushed a commit that referenced this issue Apr 25, 2024
### Issue # (if applicable)

Closes #29942

### Reason for this change

Allows existing API Destinations to be imported and attached to additional rules

### Description of changes

* Added `ApiDestination.fromApiDestinationAttributes` method

### Description of how you validated changes

Added unit and integ tests

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

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

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.