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

fix(aws-events-targets): Consume IRestApi as target #16542

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions packages/@aws-cdk/aws-events-targets/lib/api-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ export interface ApiGatewayProps extends TargetBaseProps {
}

/**
* Use an API Gateway REST APIs as a target for Amazon EventBridge rules.
* Use an API Gateway REST API as a target for Amazon EventBridge rules.
*/
export class ApiGateway implements events.IRuleTarget {
export class ApiGatewayTarget implements events.IRuleTarget {
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, none of the other classes end in Target.

I'm not sure this one should buck the trend.


constructor(public readonly restApi: api.RestApi, private readonly props?: ApiGatewayProps) {
/**
* @param iRestApi - An implementation of a Rest API to send events to
*/
constructor(public readonly iRestApi: api.IRestApi, protected readonly props?: ApiGatewayProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
constructor(public readonly iRestApi: api.IRestApi, protected readonly props?: ApiGatewayProps) {
constructor(public readonly restApi: api.IRestApi, protected readonly props?: ApiGatewayProps) {

}

/**
Expand All @@ -93,15 +96,15 @@ export class ApiGateway implements events.IRuleTarget {
throw new Error('The number of wildcards in the path does not match the number of path pathParameterValues.');
}

const restApiArn = this.restApi.arnForExecuteApi(
const restApiArn = this.iRestApi.arnForExecuteApi(
this.props?.method,
this.props?.path || '/',
this.props?.stage || this.restApi.deploymentStage.stageName,
this.props?.stage || this.iRestApi.deploymentStage.stageName,
);
return {
...(this.props ? bindBaseTargetConfig(this.props) : {}),
arn: restApiArn,
role: this.props?.eventRole || singletonEventRole(this.restApi, [new iam.PolicyStatement({
role: this.props?.eventRole || singletonEventRole(this.iRestApi, [new iam.PolicyStatement({
resources: [restApiArn],
actions: [
'execute-api:Invoke',
Expand All @@ -110,7 +113,7 @@ export class ApiGateway implements events.IRuleTarget {
})]),
deadLetterConfig: this.props?.deadLetterQueue && { arn: this.props.deadLetterQueue?.queueArn },
input: this.props?.postBody,
targetResource: this.restApi,
targetResource: this.iRestApi,
httpParameters: {
headerParameters: this.props?.headerParameters,
queryStringParameters: this.props?.queryStringParameters,
Expand All @@ -121,3 +124,19 @@ export class ApiGateway implements events.IRuleTarget {

}

/**
* Use an API Gateway REST APIs as a target for Amazon EventBridge rules.
*
* @deprecated - Use ApiGatewayTarget
*/
export class ApiGateway extends ApiGatewayTarget {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see. No, we can repurpose this class.


/**
* @param restApi - A Rest API to send events to
*/
constructor(public readonly restApi: api.RestApi, protected readonly props?: ApiGatewayProps) {
super(restApi, props);
}

}