@@ -10,6 +10,7 @@ import * as kinesis from 'aws-cdk-lib/aws-kinesis';
1010import * as s3 from 'aws-cdk-lib/aws-s3' ;
1111import * as s3n from 'aws-cdk-lib/aws-s3-notifications' ;
1212import * as apigateway from 'aws-cdk-lib/aws-apigateway' ;
13+ import * as apigatewayv2 from 'aws-cdk-lib/aws-apigatewayv2' ;
1314import * as events from 'aws-cdk-lib/aws-events' ;
1415import * as events_targets from 'aws-cdk-lib/aws-events-targets' ;
1516import * as lambda_event_sources from 'aws-cdk-lib/aws-lambda-event-sources' ;
@@ -298,6 +299,65 @@ export class PythonTracingScenariosStack extends cdk.NestedStack {
298299 } ,
299300 } ) ;
300301
302+ // Scenario 6b: Lambda > HTTP API Gateway > Lambda
303+ const httpApiConsumer = new lambda . Function ( this , `HttpApiConsumerLambda-${ runtimeName } ` , {
304+ functionName : `${ prefix } tracing-httpapi-consumer-${ runtimeName } ` ,
305+ runtime,
306+ handler : 'consumer.handler' ,
307+ code : pythonCode ,
308+ layers : [ props . layer ] ,
309+ role,
310+ timeout : cdk . Duration . seconds ( 10 ) ,
311+ logGroup : props . logGroup ,
312+ environment : baseEnvironment ,
313+ } ) ;
314+
315+ const httpApi = new apigatewayv2 . CfnApi ( this , `TracingTestHttpApi-${ runtimeName } ` , {
316+ name : `${ prefix } tracing-test-http-api-${ runtimeName } ` ,
317+ protocolType : 'HTTP' ,
318+ } ) ;
319+
320+ const httpApiIntegration = new apigatewayv2 . CfnIntegration ( this , `TracingTestHttpApiIntegration-${ runtimeName } ` , {
321+ apiId : httpApi . ref ,
322+ integrationType : 'AWS_PROXY' ,
323+ integrationUri : httpApiConsumer . functionArn ,
324+ payloadFormatVersion : '2.0' ,
325+ } ) ;
326+
327+ new apigatewayv2 . CfnRoute ( this , `TracingTestHttpApiRoute-${ runtimeName } ` , {
328+ apiId : httpApi . ref ,
329+ routeKey : 'POST /' ,
330+ target : `integrations/${ httpApiIntegration . ref } ` ,
331+ } ) ;
332+
333+ new apigatewayv2 . CfnStage ( this , `TracingTestHttpApiStage-${ runtimeName } ` , {
334+ apiId : httpApi . ref ,
335+ stageName : '$default' ,
336+ autoDeploy : true ,
337+ } ) ;
338+
339+ httpApiConsumer . addPermission ( `HttpApiInvokePermission-${ runtimeName } ` , {
340+ principal : new iam . ServicePrincipal ( 'apigateway.amazonaws.com' ) ,
341+ sourceArn : `arn:aws:execute-api:${ this . region } :${ this . account } :${ httpApi . ref } /*/*` ,
342+ } ) ;
343+
344+ const httpApiUrl = `https://${ httpApi . ref } .execute-api.${ this . region } .amazonaws.com/` ;
345+
346+ const httpApiProducer = new lambda . Function ( this , `HttpApiProducerLambda-${ runtimeName } ` , {
347+ functionName : `${ prefix } tracing-httpapi-producer-${ runtimeName } ` ,
348+ runtime,
349+ handler : 'apigateway_producer.handler' ,
350+ code : pythonCode ,
351+ layers : [ props . layer ] ,
352+ role,
353+ timeout : cdk . Duration . seconds ( 10 ) ,
354+ logGroup : props . logGroup ,
355+ environment : {
356+ ...baseEnvironment ,
357+ API_URL : httpApiUrl ,
358+ } ,
359+ } ) ;
360+
301361 // Scenario 7: Lambda > S3 > Lambda
302362 const s3Bucket = new s3 . Bucket ( this , `TracingTestS3Bucket-${ runtimeName } ` , {
303363 bucketName : `${ prefix } tracing-test-s3-bucket-${ runtimeName } ` ,
0 commit comments