From 4709a1ca76cad3895290ae6a4b63a5bb75cc67a2 Mon Sep 17 00:00:00 2001 From: Michael Sambol Date: Fri, 1 Nov 2024 17:36:11 -0700 Subject: [PATCH] Update int test --- .../test/integ.api-gateway.ts | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.api-gateway.ts b/packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.api-gateway.ts index dc27af3a912b6..7838bc5eca573 100644 --- a/packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.api-gateway.ts +++ b/packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.api-gateway.ts @@ -1,15 +1,10 @@ -import { Pipe } from '@aws-cdk/aws-pipes-alpha'; -import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha'; +import { IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha'; import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha'; import * as cdk from 'aws-cdk-lib'; import * as apigw from 'aws-cdk-lib/aws-apigateway'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import { ApiGatewayTarget } from '../lib/api-gateway'; -const app = new cdk.App(); -const stack = new cdk.Stack(app, 'aws-cdk-pipes-targets-api-gw'); -const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue'); - /* * This integration test sends a message to an SQS queue which invokes * the REST API. There is a Lambda function on the backend of the REST API. @@ -19,6 +14,29 @@ const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue'); * SQS (pipe source) --> API Gateway REST API (pipe target) --> Lambda function */ +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'aws-cdk-pipes-targets-api-gw'); +const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue'); + +// When this module is promoted from alpha, TestSource should +// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha +class TestSource implements ISource { + sourceArn: string; + sourceParameters = undefined; + constructor(private readonly queue: cdk.aws_sqs.Queue) { + this.queue = queue; + this.sourceArn = queue.queueArn; + } + bind(_pipe: IPipe): SourceConfig { + return { + sourceParameters: this.sourceParameters, + }; + } + grantRead(pipeRole: cdk.aws_iam.IRole): void { + this.queue.grantConsumeMessages(pipeRole); + } +} + const fn = new lambda.Function(stack, 'ConnectHandler', { runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', @@ -29,7 +47,7 @@ const restApi = new apigw.RestApi(stack, 'RestApi', {}); restApi.root.addResource('books').addResource('fiction').addMethod('GET', new apigw.LambdaIntegration(fn)); new Pipe(stack, 'Pipe', { - source: new SqsSource(sourceQueue), + source: new TestSource(sourceQueue), target: new ApiGatewayTarget(restApi, { method: 'GET', path: '/books/*',