-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.ts
107 lines (102 loc) · 2.76 KB
/
serverless.ts
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
import { AWS } from "@serverless/typescript";
import { ref } from "./libs/cloudformation";
import { Bucket } from "./resources/s3";
import {
getSignedUploadUrl,
getSignedDownloadUrl,
dispatchFileUploadedEvent as dispatchFileUpload,
} from "./functions/config";
import { FileTable, FileTableName, FileTableArn } from "./resources/dynamodb";
import { EventBridge } from "./resources/event-bridge";
import {
getDownloadUrlAuthorizer,
getUploadUrlAuthorizer,
onFileUploaded,
listFiles,
} from "./examples/allowMe/functions/config";
const cloudformationResources: AWS["resources"]["Resources"] = {
Bucket,
FileTable,
EventBridge,
};
const serverlessConfiguration: AWS = {
service: "S4",
frameworkVersion: ">=2.4.0",
plugins: ["serverless-webpack", "serverless-pseudo-parameters"],
provider: {
name: "aws",
runtime: "nodejs12.x",
region: "eu-west-1",
environment: { AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1" },
iamRoleStatements: [
{
Effect: "Allow",
Resource: [
{
"Fn::Join": ["", [{ "Fn::GetAtt": ["Bucket", "Arn"] }, "/*"]],
},
],
Action: ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"],
},
{
Effect: "Allow",
Resource: [{ "Fn::GetAtt": ["FileTable", "Arn"] }],
Action: [
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:DeleteItem",
"dynamodb:PutItem",
],
},
{
Effect: "Allow",
Resource: [{ "Fn::GetAtt": ["EventBridge", "Arn"] }],
Action: ["events:PutEvents"],
},
],
httpApi: {
payload: "2.0",
cors: {
allowedOrigins: ["*"],
allowedHeaders: ["Content-Type", "Origin"],
allowedMethods: ["POST", "OPTIONS", "GET"],
},
},
},
functions: {
getDownloadUrlAuthorizer,
getUploadUrlAuthorizer,
getSignedUploadUrl,
getSignedDownloadUrl,
dispatchFileUpload,
onFileUploaded,
listFiles,
},
custom: {
webpack: {
webpackConfig: "./webpack.config.js",
includeModules: true,
},
bucketName: ref({ Bucket }),
fileTableName: ref({ FileTable }),
fileTableStreamArn: { "Fn::GetAtt": ["FileTable", "StreamArn"] },
fileTableArn: { "Fn::GetAtt": ["FileTable", "Arn"] },
eventBusName: ref({ EventBridge }),
eventBridgeArn:
"arn:aws:events:#{AWS::Region}:#{AWS::AccountId}:event-bus/s4",
getSignedDownloadUrlArn: {
"Fn::GetAtt": ["GetSignedDownloadUrlLambdaFunction", "Arn"],
},
getSignedUploadUrlArn: {
"Fn::GetAtt": ["GetSignedUploadUrlLambdaFunction", "Arn"],
},
},
resources: {
Resources: cloudformationResources,
Outputs: {
FileTableName,
FileTableArn,
},
},
};
module.exports = serverlessConfiguration;