11#!/usr/bin/env python3
22import os
3-
3+ from constructs import Construct
44from aws_cdk import (
5- core as cdk ,
6- aws_apigatewayv2 as apigatewayv2 ,
7- aws_apigatewayv2_integrations as integrations ,
8- aws_lambda as lambda_ ,
5+ App ,
6+ Stack ,
7+ CfnOutput ,
8+ Duration ,
9+ aws_lambda as lambda_
910)
11+ import aws_cdk .aws_apigatewayv2_alpha as _apigw
12+ import aws_cdk .aws_apigatewayv2_integrations_alpha as _integrations
13+
1014
1115DIRNAME = os .path .dirname (__file__ )
1216
13- class ApigwHttpApiLambdaStack (cdk . Stack ):
17+ class ApigwHttpApiLambdaStack (Stack ):
1418
15- def __init__ (self , scope : cdk . Construct , construct_id : str , ** kwargs ) -> None :
19+ def __init__ (self , scope : Construct , construct_id : str , ** kwargs ) -> None :
1620 super ().__init__ (scope , construct_id , ** kwargs )
1721
1822 # Create the Lambda function to receive the request
@@ -29,25 +33,25 @@ def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
2933 )
3034
3135 # Create the HTTP API with CORS
32- http_api = apigatewayv2 .HttpApi (
36+ http_api = _apigw .HttpApi (
3337 self , "MyHttpApi" ,
34- cors_preflight = apigatewayv2 .CorsPreflightOptions (
35- allow_methods = [apigatewayv2 .CorsHttpMethod .GET ],
38+ cors_preflight = _apigw .CorsPreflightOptions (
39+ allow_methods = [_apigw .CorsHttpMethod .GET ],
3640 allow_origins = ["*" ],
37- max_age = cdk . Duration .days (10 ),
41+ max_age = Duration .days (10 ),
3842 )
3943 )
4044
4145 # Add a route to GET /
4246 http_api .add_routes (
4347 path = "/" ,
44- methods = [apigatewayv2 .HttpMethod .GET ],
45- integration = integrations . LambdaProxyIntegration ( handler = lambda_fn ),
48+ methods = [_apigw .HttpMethod .GET ],
49+ integration = _integrations . HttpLambdaIntegration ( "LambdaProxyIntegration" , handler = lambda_fn ),
4650 )
4751
4852 # Outputs
49- cdk . CfnOutput (self , "API Endpoint" , description = "API Endpoint" , value = http_api .api_endpoint )
53+ CfnOutput (self , "API Endpoint" , description = "API Endpoint" , value = http_api .api_endpoint )
5054
51- app = cdk . App ()
55+ app = App ()
5256ApigwHttpApiLambdaStack (app , "ApigwHttpApiLambdaStack" )
5357app .synth ()
0 commit comments