-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
111 lines (108 loc) · 4.1 KB
/
template.yml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: A collection of utilities that integrate with Eventbrite
Parameters:
EventbriteToken: { Type: String }
Resources:
TicketNotificationsRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyDocument:
Statement:
- Action: events:PutEvents
Effect: Allow
Resource: !Sub arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:event-bus/default
Sid: AllowDefaultEventBusPut
Version: "2012-10-17"
PolicyName: SlackRelaySnsPublish
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Eventbrite Toolkit }
TicketNotificationsSelfInvokePolicy:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action: lambda:Invoke*
Effect: Allow
Resource: !GetAtt TicketNotificationsFunction.Arn
Sid: AllowSelfInvoke
PolicyName: !Sub ${AWS::StackName}-TicketNotificationsSelfInvokePolicy
Roles:
- !Ref TicketNotificationsRole
TicketNotificationsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/ticket-notifications
Description: >-
Handles Eventbrite webhook requests and sends messages to Slack with
information about ticket sales
Environment:
Variables:
EVENTBRITE_TOKEN: !Ref EventbriteToken
FunctionUrlConfig:
AuthType: NONE
InvokeMode: BUFFERED
Handler: index.handler
MemorySize: 128
Role: !GetAtt TicketNotificationsRole.Arn
Runtime: nodejs22.x
Tags:
prx:meta:tagging-version: 2021-04-07
prx:cloudformation:stack-name: !Ref AWS::StackName
prx:cloudformation:stack-id: !Ref AWS::StackId
prx:ops:environment: Production
prx:dev:application: Eventbrite Toolkit
Timeout: 8
TicketNotificationsLogGroup:
Type: AWS::Logs::LogGroup
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
LogGroupName: !Sub /aws/lambda/${TicketNotificationsFunction}
RetentionInDays: 30
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Eventbrite Toolkit }
TicketNotificationsErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: "MINOR [Eventbrite] Ticket Notifications <prod> EXPERIENCING ERRORS"
AlarmDescription: >-
The error rate on the Eventbrite toolkit activity Slack notifications
Lambda function has exceeded 0. Some ticket activity may not be
reaching Slack channels.
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: FunctionName
Value: !Ref TicketNotificationsFunction
EvaluationPeriods: 2
MetricName: Errors
Namespace: AWS/Lambda
Period: 60
Statistic: Sum
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Eventbrite Toolkit }
Threshold: 0
TreatMissingData: notBreaching