Skip to content

Commit d0747d1

Browse files
committed
Support invoking aws-lambda with layers
Fixes serverless-components#7
1 parent c932778 commit d0747d1

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

serverless.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const outputsList = [
2727
'env',
2828
'role',
2929
'layer',
30+
'layers',
3031
'arn',
3132
'region'
3233
]
@@ -41,7 +42,8 @@ const defaults = {
4142
handler: 'handler.hello',
4243
runtime: 'nodejs10.x',
4344
env: {},
44-
region: 'us-east-1'
45+
region: 'us-east-1',
46+
layers: []
4547
}
4648

4749
class AwsLambda extends Component {

utils.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable prettier/prettier */
12
const { tmpdir } = require('os')
23
const path = require('path')
34
const archiver = require('archiver')
@@ -76,7 +77,8 @@ const createLambda = async ({
7677
zipPath,
7778
bucket,
7879
role,
79-
layer
80+
layer, // From autogenerated layer
81+
layers // Manual layers
8082
}) => {
8183
const params = {
8284
FunctionName: name,
@@ -90,11 +92,13 @@ const createLambda = async ({
9092
Timeout: timeout,
9193
Environment: {
9294
Variables: env
93-
}
95+
},
96+
Layers: layers
9497
}
9598

99+
96100
if (layer && layer.arn) {
97-
params.Layers = [layer.arn]
101+
params.Layers = [layer.arn, ...layers]
98102
}
99103

100104
if (bucket) {
@@ -119,7 +123,8 @@ const updateLambdaConfig = async ({
119123
env,
120124
description,
121125
role,
122-
layer
126+
layer, // From autogenerated layer
127+
layers // Manual layers
123128
}) => {
124129
const functionConfigParams = {
125130
FunctionName: name,
@@ -131,11 +136,12 @@ const updateLambdaConfig = async ({
131136
Timeout: timeout,
132137
Environment: {
133138
Variables: env
134-
}
139+
},
140+
Layers: layers
135141
}
136142

137143
if (layer && layer.arn) {
138-
functionConfigParams.Layers = [layer.arn]
144+
functionConfigParams.Layers = [layer.arn, ...layers]
139145
}
140146

141147
const res = await lambda.updateFunctionConfiguration(functionConfigParams).promise()

0 commit comments

Comments
 (0)