-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
111 lines (102 loc) · 2.59 KB
/
serverless.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
service: mdcloud-serverless
custom: ${file(./config.json)}
provider:
name: aws
runtime: nodejs6.10
memorySize: 128
timeout: 20
region: us-east-1
environment:
apikey: ${self:custom.apikey}
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:*"
Resource: "*"
- Effect: "Allow"
Action:
- sqs:DeleteMessage
- sqs:ReceiveMessage
- sqs:SendMessage
Resource: "arn:aws:sqs:*:*:${self:custom.sqs}"
- Effect: "Allow"
Action:
- "sns:*"
Resource: "arn:aws:sns:*:*:${self:custom.snsEmail}"
- Effect: "Allow"
Action:
- "lambda:InvokeFunction"
Resource:
- "*"
package:
exclude:
- node_modules/aws-sdk/**
- event_samples/**
- .vscode/**
functions:
task:
handler: task.handler
name: task
environment:
sqs: ${self:custom.sqs}
scan:
handler: scan.handler
name: scan
environment:
sqs: ${self:custom.sqs}
events:
- s3:
bucket: ${self:custom.bucket}
event: s3:ObjectCreated:*
worker:
handler: worker.handler
name: worker
environment:
sqs: ${self:custom.sqs}
lambda: task
events:
- schedule: rate(1 minute)
- sns: ${self:custom.sns}
resources:
Resources:
BacklogQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:custom.sqs}
MessageRetentionPeriod: '1209600'
VisibilityTimeout: '60'
RedrivePolicy:
deadLetterTargetArn:
Fn::GetAtt:
- DeadLetterQueue
- Arn
maxReceiveCount: '10'
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:custom.sqs}-dead-letter-queue
MessageRetentionPeriod: '1209600'
QueueDepthAlarmOver100:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: Alarm if queue depth grows beyond 100 messages
Namespace: AWS/SQS
MetricName: NumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: ${self:custom.sqs}
Statistic: Sum
Period: '60'
EvaluationPeriods: '1'
Threshold: '100'
ComparisonOperator: GreaterThanOrEqualToThreshold
AlarmActions:
- { "Fn::Join" : ["", ["arn:aws:sns:${self:provider.region}:", { "Ref" : "AWS::AccountId" }, ":${self:custom.sns}" ] ] }
MailQueue:
Type: AWS::SNS::Topic
Properties:
DisplayName: "Serverless Mail"
TopicName: ${self:custom.snsEmail}
Subscription:
- Endpoint: ${self:custom.mailTo}
Protocol: "email"