-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathapp.py
55 lines (47 loc) · 1.8 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from constructs import Construct
from aws_cdk import (
App, Stack,
aws_lambda as _lambda,
aws_apigateway as _apigw
)
class ApiCorsLambdaStack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
base_lambda = _lambda.Function(self, 'ApiCorsLambda',
handler='lambda-handler.handler',
runtime=_lambda.Runtime.PYTHON_3_7,
code=_lambda.Code.from_asset('lambda'))
base_api = _apigw.RestApi(self, 'ApiGatewayWithCors',
rest_api_name='ApiGatewayWithCors')
example_entity = base_api.root.add_resource(
'example',
default_cors_preflight_options=_apigw.CorsOptions(
allow_methods=['GET', 'OPTIONS'],
allow_origins=_apigw.Cors.ALL_ORIGINS)
)
example_entity_lambda_integration = _apigw.LambdaIntegration(
base_lambda,
proxy=False,
integration_responses=[
_apigw.IntegrationResponse(
status_code="200",
response_parameters={
'method.response.header.Access-Control-Allow-Origin': "'*'"
}
)
]
)
example_entity.add_method(
'GET', example_entity_lambda_integration,
method_responses=[
_apigw.MethodResponse(
status_code="200",
response_parameters={
'method.response.header.Access-Control-Allow-Origin': True
}
)
]
)
app = App()
ApiCorsLambdaStack(app, "ApiCorsLambdaStack")
app.synth()