Skip to content

Commit

Permalink
Support invoking aws-lambda with layers
Browse files Browse the repository at this point in the history
  • Loading branch information
ration committed Feb 14, 2020
1 parent c932778 commit 448e723
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const defaults = {
handler: 'handler.hello',
runtime: 'nodejs10.x',
env: {},
region: 'us-east-1'
region: 'us-east-1',
layers: []
}

class AwsLambda extends Component {
Expand Down
18 changes: 12 additions & 6 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
const { tmpdir } = require('os')
const path = require('path')
const archiver = require('archiver')
Expand Down Expand Up @@ -76,7 +77,8 @@ const createLambda = async ({
zipPath,
bucket,
role,
layer
layer, // From autogenerated layer
layers // Manual layers
}) => {
const params = {
FunctionName: name,
Expand All @@ -90,11 +92,13 @@ const createLambda = async ({
Timeout: timeout,
Environment: {
Variables: env
}
},
Layers: layers
}


if (layer && layer.arn) {
params.Layers = [layer.arn]
params.Layers = [layer.arn, ...layers]
}

if (bucket) {
Expand All @@ -119,7 +123,8 @@ const updateLambdaConfig = async ({
env,
description,
role,
layer
layer, // From autogenerated layer
layers // Manual layers
}) => {
const functionConfigParams = {
FunctionName: name,
Expand All @@ -131,11 +136,12 @@ const updateLambdaConfig = async ({
Timeout: timeout,
Environment: {
Variables: env
}
},
Layers: layers
}

if (layer && layer.arn) {
functionConfigParams.Layers = [layer.arn]
functionConfigParams.Layers = [layer.arn, ...layers]
}

const res = await lambda.updateFunctionConfiguration(functionConfigParams).promise()
Expand Down

0 comments on commit 448e723

Please sign in to comment.