-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.yaml
67 lines (62 loc) · 2.08 KB
/
template.yaml
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
61
62
63
64
65
66
67
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: AWS SAM Template for a Lambda function triggered by cron and interacting with S3.
Parameters:
AppDataJsonPath:
Type: String
Description: "Path to the app data JSON file in the S3 bucket"
LeetbotSlackChannel:
Type: String
Description: "Slack channel for the Leetbot app"
LeetbotSlackToken:
Type: String
Description: "Slack token for the Leetbot app"
LeetbotSlackAlertsEnabled:
Type: String
Description: "Slack channel for Leetbot alerts"
LeetbotQuestionDifficulty:
Type: String
Description: "Difficulty level of Leetbot questions, any combination of easy, medium, hard."
Resources:
LeetbotLambda:
Type: AWS::Serverless::Function
Properties:
Handler: leetbot.handler
Runtime: python3.12
CodeUri: ./leetbot/
Timeout: 120
MemorySize: 128
ReservedConcurrentExecutions: 1
Environment:
Variables:
LEETBOT_CHANNEL: !Ref LeetbotSlackChannel
LEETBOT_JSON_PATH: !Sub "s3://${LeetbotBucket}/${AppDataJsonPath}"
LEETBOT_QUESTION_DIFFICULTY: !Ref LeetbotQuestionDifficulty
LEETBOT_SEND_CHANNEL_ALERT: !Ref LeetbotSlackAlertsEnabled
LEETBOT_SLACK_TOKEN: !Ref LeetbotSlackToken
Policies:
- S3ReadPolicy:
BucketName: !Ref LeetbotBucket
- S3WritePolicy:
BucketName: !Ref LeetbotBucket
Events:
LeetbotCron:
Type: ScheduleV2
Properties:
Description: "Leetbot cron job"
RetryPolicy:
MaximumRetryAttempts: 0
MaximumEventAgeInSeconds: 60
ScheduleExpressionTimezone: UTC
ScheduleExpression: cron(0 17 * * ? *) # Every day at noon PT (adjusted to UTC)
LeetbotBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: "leetbot-bucket"
Outputs:
LambdaFunctionArn:
Description: "ARN of the Lambda function"
Value: !GetAtt LeetbotLambda.Arn
S3BucketName:
Description: "Name of the S3 bucket"
Value: !Ref LeetbotBucket