-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Expand file tree
/
Copy pathserverless.ts
More file actions
105 lines (102 loc) · 2.79 KB
/
serverless.ts
File metadata and controls
105 lines (102 loc) · 2.79 KB
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
import type { AWS } from "@serverless/typescript";
const serverlessConfiguration: AWS = {
service: "aws-node-typescript-multi-instance-lambda",
frameworkVersion: "3",
configValidationMode: "error",
plugins: ["serverless-webpack"],
provider: {
name: "aws",
runtime: "nodejs18.x",
// region: "ap-southeast-2",
// Rename CloudFormation stack to include the instance name
stackName: "${self:service}-${param:instance}-${sls:stage}",
},
functions: {
hello: {
// Rename function to include the instance name
name: "${self:service}-${param:instance}-${sls:stage}-hello",
handler: "handler.hello",
environment: {
INSTANCE_NAME: "${param:instance}",
},
},
},
resources: {
Resources: {
IamRoleLambdaExecution: {
Type: "AWS::IAM::Role",
Properties: {
Policies: [
{
PolicyName: {
"Fn::Join": [
"-",
[
"${self:service}",
"${param:instance}",
"${sls:stage}",
"lambda",
],
],
},
},
],
// Include instance name to avoid resource collision between instances
RoleName: {
"Fn::Join": [
"-",
[
// "${self:service}",
"multi-instance", // shorten service name due to 64-character "roleName" length requirement
"${param:instance}",
"${sls:stage}",
{
Ref: "AWS::Region",
},
"lambdaRole",
],
],
},
},
},
},
Outputs: {
// Rename output export names to include instance name
// https://github.com/serverless/serverless/issues/9361#issuecomment-884602588
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html
HelloLambdaFunctionQualifiedArn: {
Export: {
Name: {
"Fn::Join": [
"-",
[
"sls",
"${self:service}",
"${param:instance}",
"${sls:stage}",
"HelloLambdaFunctionQualifiedArn",
],
],
},
},
},
ServerlessDeploymentBucketName: {
Export: {
Name: {
"Fn::Join": [
"-",
[
"sls",
"${self:service}",
"${param:instance}",
"${sls:stage}",
"ServerlessDeploymentBucketName",
],
],
},
},
},
},
},
};
module.exports = serverlessConfiguration;