-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
76 lines (71 loc) · 2.02 KB
/
template.yaml
File metadata and controls
76 lines (71 loc) · 2.02 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
MastodonUrl:
Description: URL of the target Mastodon instance
Type: String
MastodonToken:
Description: Mastodon API security token
Type: String
OpenaiApiKey:
Description: OpenAI API key
Type: String
AlarmEmail:
Description: Email address to receive error alarm notifications
Type: String
Resources:
DailyWikiPicFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambda/
Handler: app.lambda_handler
Runtime: python3.13
MemorySize: 128
Timeout: 900
Environment:
Variables:
MASTODON_URL: !Ref MastodonUrl
MASTODON_TOKEN: !Ref MastodonToken
OPENAI_API_KEY: !Ref OpenaiApiKey
POWERTOOLS_SERVICE_NAME: DailyWikiPicLambda
POWERTOOLS_LOG_LEVEL: INFO
Events:
ScheduleEvent:
Type: Schedule
Properties:
Schedule: cron(0 17 * * ? *)
DailyWikiPicFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${DailyWikiPicFunction}"
RetentionInDays: 14
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Protocol: email
Endpoint: !Ref AlarmEmail
ErrorMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref DailyWikiPicFunctionLogGroup
FilterPattern: "?ERROR ?Error ?error"
MetricTransformations:
- MetricName: DailyWikiPicErrors
MetricNamespace: DailyWikiPic
MetricValue: "1"
DefaultValue: 0
ErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: DailyWikiPic Lambda function logged an error
MetricName: DailyWikiPicErrors
Namespace: DailyWikiPic
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref AlarmTopic