diff --git a/packages/aws-cdk-lib/aws-events-targets/lib/api-gateway.ts b/packages/aws-cdk-lib/aws-events-targets/lib/api-gateway.ts index 11fd71abcf056..fb9027b2a60c3 100644 --- a/packages/aws-cdk-lib/aws-events-targets/lib/api-gateway.ts +++ b/packages/aws-cdk-lib/aws-events-targets/lib/api-gateway.ts @@ -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 restApi - IRestApi implementation to use as event target + * @param props - Properties to configure the APIGatway target + */ + constructor(public readonly restApi: api.IRestApi, private readonly props?: ApiGatewayProps) { } /** diff --git a/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts b/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts index dcd598bbfa89a..ddf0d729c1c27 100644 --- a/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts +++ b/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts @@ -8,6 +8,62 @@ import * as sqs from '../../../aws-sqs'; import * as cdk from '../../../core'; import * as targets from '../../lib'; +test('use a SpecRestApi APIGateway event rule target', () => { + // GIVEN + const stack = new cdk.Stack(); + const specRestApi = newTestSpecRestApi(stack); + const rule = new events.Rule(stack, 'Rule', { + schedule: events.Schedule.rate(cdk.Duration.minutes(1)), + }); + + // WHEN + rule.addTarget(new targets.ApiGateway(specRestApi)); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', { + Targets: [ + { + Arn: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':execute-api:', + { + Ref: 'AWS::Region', + }, + ':', + { + Ref: 'AWS::AccountId', + }, + ':', + { + Ref: 'MySpecRestApiFB7DB2AB', + }, + '/', + { + Ref: 'MySpecRestApiDeploymentStageprod8522A503', + }, + '/*/', + ], + ], + }, + HttpParameters: {}, + Id: 'Target0', + RoleArn: { + 'Fn::GetAtt': [ + 'MySpecRestApiEventsRole25C1D10F', + 'Arn', + ], + }, + }, + ], + }); +}); + test('use api gateway rest api as an event rule target', () => { // GIVEN const stack = new cdk.Stack(); @@ -261,3 +317,12 @@ function newTestRestApi(scope: constructs.Construct, suffix = '') { handler: lambdaFunctin, } ); } + +function newTestSpecRestApi(scope: constructs.Construct, suffix = '') { + return new api.SpecRestApi( scope, `MySpecRestApi${suffix}`, { + apiDefinition: api.ApiDefinition.fromInline({ + openapi: '3.0.2', + paths: {}, + }), + } ); +}