-
Notifications
You must be signed in to change notification settings - Fork 7
/
serverless.yml
174 lines (156 loc) · 4.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
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
163
164
165
166
167
168
169
170
171
172
173
174
service: graphql
provider:
name: aws
runtime: nodejs18.x
region: us-east-1
stage: ${opt:stage, 'development'}
endpointType: PRIVATE
memorySize: 512
environment: ${file(./serverless-configs/env.yml):${self:provider.stage}}
vpc:
securityGroupIds:
- Fn::ImportValue: ${self:provider.stage}-GraphQLLambdaSecurityGroup
subnetIds:
- ${env:SUBNET_ID_A, 'subnetIdA'}
- ${env:SUBNET_ID_B, 'subnetIdB'}
iam:
role:
Fn::ImportValue: ${self:provider.stage}-GraphQLApplicationRole
# Package each lambda into individual zip files. This reduces the size of
# each lambda but increases the complexity of the compilation process slightly
package:
individually: true
patterns:
- '!venv/**'
- '!__pycache__/**'
plugins:
- serverless-esbuild
- serverless-offline
- serverless-plugin-log-subscription
- serverless-python-requirements
functions:
graphql:
handler: src/graphql/handler.default
timeout: ${env:LAMBDA_TIMEOUT, '30'}
events:
- http:
path: api
method: post
cors:
origin: '*'
headers:
- Client-Id
- Content-Type
- X-Request-Id
- http:
path: api
method: get
cors: true
cloudfrontToCloudwatch:
handler: src/cloudfrontToCloudwatch/handler.default
timeout: 300
role: IamRoleCustomResourcesLambdaExecution
events:
- s3:
bucket: ${env:CLOUDFRONT_BUCKET_NAME, ''}
event: s3:ObjectCreated:*
existing: true
rules:
- suffix: .gz
- prefix:
Fn::Join: [
"/", [
"cloudfront/AWSLogs",
{
"Ref": "AWS::AccountId"
},
"${self:provider.region}/graphql_apigw/"
]
]
earthdataVarinfo:
runtime: python3.9
handler: src/earthdataVarinfo/handler.main
ephemeralStorageSize: 2048
timeout: ${env:LAMBDA_TIMEOUT, '30'}
package:
patterns:
- '!node_modules/**'
resources:
Resources:
# This role must not be changed -- if it is removed Serverless will attempt to automatically
# recreate it and deployments will fail because our permissions boundary does not allow for
# creation of roles. This role is used specifically for S3 Lambda triggers that use existing
# buckets, which is what we're using for forwarding cloudfront logs to Splunk.
IamRoleCustomResourcesLambdaExecution:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
PermissionsBoundary:
Fn::Join: [
"", [
"arn:aws:iam::",
{
"Ref": "AWS::AccountId"
},
":policy/NGAPShRoleBoundary"
]
]
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
S3CloudfrontLogToCloudwatchPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Action:
- "s3:GetBucketLocation"
- "s3:ListBucket"
- "s3:ListAllMyBuckets"
- "s3:GetObject"
Effect: "Allow"
Resource: "*"
PolicyName: ${self:provider.stage}-S3CloudfrontLogToCloudwatchPolicy
Roles:
- Ref: IamRoleCustomResourcesLambdaExecution
configValidationMode: error
custom:
siteName: graphql-${self:provider.stage}
# Default is 3000 so to avoid conflicts with other applications we'll define a new port
serverless-offline:
httpPort: 3013
lambdaPort: 3014
reloadHandler: true
# Uncomment useInProcess to enable in-process run mode
# https://github.com/dherault/serverless-offline#run-modes
# useInProcess: true
minifyBuild:
development: false
sit: true
uat: true
prod: true
esbuild:
loader:
.graphql: text
.gql: text
minify: ${self:custom.minifyBuild.${self:provider.stage}}
exclude:
- '@aws-sdk/client-lambda'
- '@aws-sdk/client-s3'
# Forward logs to Splunk
logSubscription:
enabled: true
destinationArn: ${env:LOG_DESTINATION_ARN, ''}
# Compile Python modules on docker only on non-linux environments
pythonRequirements:
dockerizePip: non-linux
zip: true
slim: true