Repository navigation
Expand file tree
/
Copy pathaws_python_stack.py
More file actions
60 lines (52 loc) · 1.63 KB
/
Copy pathaws_python_stack.py
File metadata and controls
60 lines (52 loc) · 1.63 KB
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
56
57
58
59
60
from aws_cdk import (
# Duration,
Stack,
# aws_sqs as sqs,
aws_lambda as _lambda,
aws_apigateway as apigw,
aws_dynamodb as dynamodb
)
from constructs import Construct
class AwsPythonStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# The code that defines your stack goes here
# example resource
# queue = sqs.Queue(
# self, "AwsPythonQueue",
# visibility_timeout=Duration.seconds(300),
# )
table = dynamodb.Table(
self,
"VisitorsTable",
partition_key={
"name": "key",
"type": dynamodb.AttributeType.STRING
},
billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
)
fn = _lambda.Function(
self,
"MyFunction",
runtime=_lambda.Runtime.PYTHON_3_14,
handler="main.handle_requests",
code=_lambda.Code.from_asset("app"),
environment={
"TABLE_NAME": table.table_name,
}
)
table.grant_read_data(fn)
fn_url = fn.add_function_url(
auth_type=_lambda.FunctionUrlAuthType.NONE,
cors=_lambda.FunctionUrlCorsOptions(
allowed_methods=[_lambda.HttpMethod.GET],
allowed_origins=["*"],
allowed_headers=["*"]
)
)
endpoint = apigw.LambdaRestApi(
self,
"ApiGwEndpoint",
handler=fn,
rest_api_name="HelloApi",
)