-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yaml
136 lines (122 loc) · 3.14 KB
/
serverless.yaml
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
service: push-code
provider:
name: aws
runtime: rust
memorySize: 128
stage: prod
region: us-west-1
iamRoleStatements:
- Effect: "Allow"
Action:
- sqs:*
Resource:
- !GetAtt WorkQueue.Arn
- Effect: "Allow"
Action:
- secretsmanager:GetSecretValue
Resource:
- !Ref GitCredential
- Effect: "Allow"
Action:
- s3:PutObject
Resource:
- !Join
- ""
- - !GetAtt SourceStore.Arn
- "/*"
environment:
PUSHCODE_WORK_QUEUE: !Ref WorkQueue
CJ_PUSHCODE_GIT_CREDENTIALS_ID: !Join
- "/"
- - !Ref AWS::StackName
- GitCredential
CJ_PUSHCODE_SOURCE_BUCKET: !Ref SourceStore
RUST_BACKTRACE: "1"
package:
individually: true
plugins:
- serverless-rust
functions:
accept:
# handler value syntax is `{cargo-package-name}.{bin-name}`
# or `{cargo-package-name}` for short when you are building a
# default bin for a given package.
handler: aws-push-code.accept
events:
- http:
path: '/push-code'
method: POST
work:
handler: aws-push-code.work
memorySize: 2048
events:
- sqs:
arn: !GetAtt WorkQueue.Arn
batchSize: 1
# onError: !Ref ErrorTopic
vpc:
securityGroupIds:
- !ImportValue network-AttachedNetworkDefaultSecurityGroup
subnetIds:
- !ImportValue network-AttachedNetworkLeftSubnet
- !ImportValue network-AttachedNetworkRightSubnet
resources:
Resources:
WorkQueue:
Type: AWS::SQS::Queue
Properties:
RedrivePolicy:
deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
maxReceiveCount : 2
SourceStore:
Type: AWS::S3::Bucket
Properties:
VersioningConfiguration:
Status: Enabled
SourceStoreReadPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
# Annoying! Cannot use YAML here. Serverless is doing something that causes it to be invalid
PolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:ListBucket",
"s3:GetBucketVersioning"
],
"Resource": [
"Fn::Join": ["", [{"Fn::GetAtt": "SourceStore.Arn"}, "/*"]],
{"Fn::GetAtt": "SourceStore.Arn"}
]
}
]
}
GitCredential:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Join
- "/"
- - !Ref AWS::StackName
- GitCredential
SecretString: "REPLACEME"
DeadLetterQueue:
Type: AWS::SQS::Queue
Outputs:
SourceStore:
Value: !Ref SourceStore
Export:
Name: !Join
- ":"
- - !Ref AWS::StackName
- SourceStore
SourceStoreReadPolicyArn:
Value: !Ref SourceStoreReadPolicy
Export:
Name: !Join
- ":"
- - !Ref AWS::StackName
- SourceStoreReadPolicyArn