Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit c9858b3

Browse files
authored
Merge pull request #2 from hypexr/master
deployLambda supports specifying a vpc configuration and waiting for pending lambda changes to complete
2 parents 4c5da67 + 87a773b commit c9858b3

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ const lambdaParams = {
172172
roleArn: 'aws:iam:role:arn:xxx', // required
173173
lambdaSrc: 'path/to/lambda/directory' // required. could also be a buffer of a zip file
174174
memory: 512 // optional, along with the other lambda config
175+
vpcConfig: // optional, specify a VPC
176+
securityGroupIds:
177+
- sg-xxx
178+
subnetIds:
179+
- subnet-xxx
180+
- subnet-xxx
175181
}
176182

177183
const { lambdaArn, lambdaSize, lambdaSha } = await aws.utils.updateOrCreateLambda(params)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@serverless/aws-sdk",
3-
"version": "5.1.0",
3+
"version": "5.2.0",
44
"description": "Powerful Serverless Utilities",
55
"main": "src/index.js",
66
"author": "Serverless, Inc.",

src/deployLambda.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
const fs = require('fs')
22
const { sleep, zip } = require('./utils')
33

4+
5+
const getVpcConfig = (vpcConfig) => {
6+
if (vpcConfig == 'undefined' || vpcConfig == null) {
7+
return {
8+
SecurityGroupIds: [],
9+
SubnetIds: []
10+
}
11+
}
12+
13+
return {
14+
SecurityGroupIds: vpcConfig.securityGroupIds,
15+
SubnetIds: vpcConfig.subnetIds
16+
}
17+
}
18+
419
const updateOrCreateLambda = async (aws, params = {}) => {
520
try {
621
if (!params.lambdaName) {
@@ -31,6 +46,8 @@ const updateOrCreateLambda = async (aws, params = {}) => {
3146

3247
const lambda = new aws.Lambda()
3348

49+
const vpcConfig = getVpcConfig(params.vpcConfig)
50+
3451
try {
3552
const updateFunctionConfigurationParams = {
3653
FunctionName: params.lambdaName, // required
@@ -43,11 +60,15 @@ const updateOrCreateLambda = async (aws, params = {}) => {
4360
Runtime: params.runtime || 'nodejs12.x',
4461
Environment: {
4562
Variables: params.env || {}
46-
}
63+
},
64+
VpcConfig: vpcConfig
4765
}
4866

4967
await lambda.updateFunctionConfiguration(updateFunctionConfigurationParams).promise()
5068

69+
// Updates (like vpc changes) need to complete before calling updateFunctionCode
70+
await lambda.waitFor('functionUpdated', { FunctionName: params.lambdaName }).promise()
71+
5172
const updateFunctionCodeParams = {
5273
FunctionName: params.lambdaName, // required
5374
ZipFile: params.lambdaSrc, // required
@@ -80,7 +101,8 @@ const updateOrCreateLambda = async (aws, params = {}) => {
80101
Timeout: params.timeout || 300,
81102
Layers: params.layers || [],
82103
Runtime: params.runtime || 'nodejs12.x',
83-
Publish: params.publish === true ? true : false
104+
Publish: params.publish === true ? true : false,
105+
VpcConfig: vpcConfig
84106
}
85107

86108
const lambdaRes = await lambda.createFunction(createFunctionParams).promise()

0 commit comments

Comments
 (0)