Skip to content

Commit

Permalink
fix(aws-events-targets): Consume IRestApi as target
Browse files Browse the repository at this point in the history
issue: aws#16423
  • Loading branch information
Neel Krishna committed Mar 7, 2024
1 parent 9c82bca commit d851857
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/aws-cdk-lib/aws-events-targets/lib/api-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export interface ApiGatewayProps extends TargetBaseProps {
*/
export class ApiGateway implements events.IRuleTarget {

constructor(public readonly restApi: api.RestApi, private readonly props?: ApiGatewayProps) {
/**
* @param iRestApi - IRestApi implementation to use as event target
* @param props - Properties to configure the APIGatway target
*/
constructor(public readonly iRestApi: api.IRestApi, private readonly props?: ApiGatewayProps) {
}

/**
Expand All @@ -93,13 +97,13 @@ 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,
);

const role = this.props?.eventRole || singletonEventRole(this.restApi);
const role = this.props?.eventRole || singletonEventRole(this.iRestApi);
role.addToPrincipalPolicy(new iam.PolicyStatement({
resources: [restApiArn],
actions: [
Expand All @@ -114,7 +118,7 @@ export class ApiGateway implements events.IRuleTarget {
role,
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 Down

0 comments on commit d851857

Please sign in to comment.