-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverless.yml
118 lines (108 loc) · 2.8 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
112
113
114
115
116
117
118
service: async-file-upload
configValidationMode: error
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
region: us-east-1
logRetentionInDays: 7
iam:
role:
statements:
- Effect: Allow
Action: s3:*
Resource: '*'
functions:
scheduleUpload:
handler: handlers/scheduleUpload.handler
events:
- httpApi:
path: /schedule-upload
method: post
iamRoleStatements:
- Effect: Allow
Action: states:StartExecution
Resource: !Ref UploadAsync
- Effect: Allow
Action: s3:*
Resource: '*'
environment:
STEP_FUNCTION_UPLOAD_ASYNC_ARN: !Ref UploadAsync
UPLOAD_BUCKET_NAME: !Ref UploadBucket
uploadToThirdParty:
handler: handlers/uploadToThirdParty.handler
deleteS3File:
handler: handlers/deleteS3File.handler
stepFunctions:
stateMachines:
UploadAsync:
name: UploadAsync
definition:
StartAt: UploadToThirdParty
States:
UploadToThirdParty:
Type: Task
Resource:
Fn::GetAtt: [uploadToThirdParty, Arn]
Retry:
- ErrorEquals:
- States.ALL
IntervalSeconds: 4
MaxAttempts: 6
BackoffRate: 1.1
Catch:
- ErrorEquals:
- States.ALL
ResultPath: $.taskresult
Next: SQSDeadLetter
ResultPath: null
Next: DeleteS3File
DeleteS3File:
Type: Task
Resource:
Fn::GetAtt: [deleteS3File, Arn]
End: true
SQSDeadLetter:
Type: Task
Resource: arn:aws:states:::sqs:sendMessage
Parameters:
QueueUrl:
Ref: DeadLetterQueue
MessageBody.$: $
# MessageAttributes:
# FailedFile:
# DataType: String
# StringValue: filex
# FailReason:
# DataType: String
# StringValue: xyz
Next: FailRetries
FailRetries:
Type: Fail
Cause: Failed after multiple retries. Check deadletter queue
resources:
Resources:
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: DeadLetterQueue-${sls:stage}
UploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: upload-flaviostutz-${sls:stage}
AccessControl: Private
custom:
esbuild:
minify: false
bundle: true
sourcemap: true
watch:
pattern:
['**/*.js']
ignore: ['.serverless/**/*', '.build', '.esbuild']
packager: npm
plugins:
- serverless-esbuild
- serverless-step-functions
- serverless-iam-roles-per-function
- serverless-offline