-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
app.py
40 lines (33 loc) · 1.11 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
from aws_cdk import (
aws_events as events,
aws_lambda as lambda_,
aws_events_targets as targets,
App, Duration, Stack
)
class LambdaCronStack(Stack):
def __init__(self, app: App, id: str) -> None:
super().__init__(app, id)
with open("lambda-handler.py", encoding="utf8") as fp:
handler_code = fp.read()
lambdaFn = lambda_.Function(
self, "Singleton",
code=lambda_.InlineCode(handler_code),
handler="index.main",
timeout=Duration.seconds(300),
runtime=lambda_.Runtime.PYTHON_3_12,
)
# Run every day at 6PM UTC
# See https://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html
rule = events.Rule(
self, "Rule",
schedule=events.Schedule.cron(
minute='0',
hour='18',
month='*',
week_day='MON-FRI',
year='*'),
)
rule.add_target(targets.LambdaFunction(lambdaFn))
app = App()
LambdaCronStack(app, "LambdaCronExample")
app.synth()