-
Notifications
You must be signed in to change notification settings - Fork 33
/
serverless.yml
162 lines (156 loc) · 4.62 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
service: localstack-demo
plugins:
- serverless-deployment-bucket
- serverless-localstack
# Note: Although there's some more popular S3 sync plugins out there, most of them failed on LocalStack with:
# "Error: Non-file stream objects are not supported with SigV4"
# at Object.computeSha256 (node_modules/aws-sdk/lib/util.js:754:23)
- serverless-sync-s3
provider:
name: aws
stage: ${opt:stage,'local'}
region: us-east-1
stackName: demo1
timeout: 15
deploymentBucket:
name: ${self:custom.deploymentBucket.${self:provider.stage}}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:*
Resource: 'arn:aws:dynamodb:us-east-1:*:table/appRequests'
- Effect: Allow
Action:
- sqs:*
Resource: 'arn:aws:sqs:us-east-1:*:requestQueue'
- Effect: Allow
Action:
- states:*
Resource: 'arn:aws:states:us-east-1:*:stateMachine:*'
- Effect: Allow
Action:
- s3:*
Resource: !Sub 'arn:aws:s3:::${self:custom.archiveBucket.${self:provider.stage}}/*'
package:
excludeDevDependencies: true
exclude:
- ./**
- "!demo/**"
- "!node_modules/uuid/**"
custom:
region: us-east-1
accountID: '000000000000'
localstack:
stages: [local]
host: http://127.0.0.1
debug: true
# Note: enable this configuration to automatically start up a LocalStack container in the background
# autostart: true
# lambda:
# mountCode: true
deploymentBucket:
local: localstack-test-bucket
aws: localstack-test-bucket-53194
archiveBucket:
local: archive-bucket
aws: localstack-demo-archive-bucket-53194
syncS3:
- bucketName: ${self:custom.archiveBucket.${self:provider.stage}}
localDir: demo/web
functions:
httpHandleRequest:
handler: demo/lambdas/app.handleRequest
runtime: nodejs14.x
events:
- http:
path: /requests
method: post
cors: true
- http:
path: /requests
method: get
cors: true
sqsHandleItem:
handler: demo/lambdas/worker.triggerProcessing
runtime: ruby2.7
environment:
STATE_MACHINE_ARN: !Sub '${processingStateMachine.Arn}'
events:
- sqs:
arn:
Fn::GetAtt: [requestQueue, Arn]
backendProcessRequest:
handler: demo/lambdas/processing.handle_request
runtime: python3.7
backendArchiveResult:
handler: demo/lambdas/processing.archive_result
runtime: python3.7
environment:
ARCHIVE_BUCKET: ${self:custom.archiveBucket.${self:provider.stage}}
resources:
Resources:
appDatabase:
Type: AWS::DynamoDB::Table
Properties:
TableName: appRequests
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: requestID
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: requestID
KeyType: RANGE
archiveBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.archiveBucket.${self:provider.stage}}
requestQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: requestQueue
processingStateMachine:
Type: AWS::StepFunctions::StateMachine
Properties:
StateMachineName: processingStateMachine
RoleArn: !Sub '${processingStateMachineRole.Arn}'
DefinitionString: !Sub |
{
"StartAt": "ProcessRequest",
"States": {
"ProcessRequest": {
"Type": "Task",
"Resource": "${BackendProcessRequestLambdaFunction.Arn}",
"Next": "ArchiveResult"
},
"ArchiveResult": {
"Type": "Task",
"Resource": "${BackendArchiveResultLambdaFunction.Arn}",
"End": true
}
}
}
processingStateMachineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: !Sub 'states.${AWS::Region}.amazonaws.com'
Action: 'sts:AssumeRole'
Policies:
- PolicyName: lambda
PolicyDocument:
Statement:
- Effect: Allow
Action: 'lambda:InvokeFunction'
Resource:
- !Sub '${BackendProcessRequestLambdaFunction.Arn}'
- !Sub '${BackendArchiveResultLambdaFunction.Arn}'