1
1
#!/usr/bin/env python3
2
2
import os
3
-
3
+ from constructs import Construct
4
4
from 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_
9
10
)
11
+ import aws_cdk .aws_apigatewayv2_alpha as _apigw
12
+ import aws_cdk .aws_apigatewayv2_integrations_alpha as _integrations
13
+
10
14
11
15
DIRNAME = os .path .dirname (__file__ )
12
16
13
- class ApigwHttpApiLambdaStack (cdk . Stack ):
17
+ class ApigwHttpApiLambdaStack (Stack ):
14
18
15
- def __init__ (self , scope : cdk . Construct , construct_id : str , ** kwargs ) -> None :
19
+ def __init__ (self , scope : Construct , construct_id : str , ** kwargs ) -> None :
16
20
super ().__init__ (scope , construct_id , ** kwargs )
17
21
18
22
# Create the Lambda function to receive the request
@@ -29,25 +33,25 @@ def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
29
33
)
30
34
31
35
# Create the HTTP API with CORS
32
- http_api = apigatewayv2 .HttpApi (
36
+ http_api = _apigw .HttpApi (
33
37
self , "MyHttpApi" ,
34
- cors_preflight = apigatewayv2 .CorsPreflightOptions (
35
- allow_methods = [apigatewayv2 .CorsHttpMethod .GET ],
38
+ cors_preflight = _apigw .CorsPreflightOptions (
39
+ allow_methods = [_apigw .CorsHttpMethod .GET ],
36
40
allow_origins = ["*" ],
37
- max_age = cdk . Duration .days (10 ),
41
+ max_age = Duration .days (10 ),
38
42
)
39
43
)
40
44
41
45
# Add a route to GET /
42
46
http_api .add_routes (
43
47
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 ),
46
50
)
47
51
48
52
# 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 )
50
54
51
- app = cdk . App ()
55
+ app = App ()
52
56
ApigwHttpApiLambdaStack (app , "ApigwHttpApiLambdaStack" )
53
57
app .synth ()
0 commit comments