1
1
const fs = require ( 'fs' )
2
2
const { sleep, zip } = require ( './utils' )
3
3
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
+
4
19
const updateOrCreateLambda = async ( aws , params = { } ) => {
5
20
try {
6
21
if ( ! params . lambdaName ) {
@@ -31,6 +46,8 @@ const updateOrCreateLambda = async (aws, params = {}) => {
31
46
32
47
const lambda = new aws . Lambda ( )
33
48
49
+ const vpcConfig = getVpcConfig ( params . vpcConfig )
50
+
34
51
try {
35
52
const updateFunctionConfigurationParams = {
36
53
FunctionName : params . lambdaName , // required
@@ -43,11 +60,15 @@ const updateOrCreateLambda = async (aws, params = {}) => {
43
60
Runtime : params . runtime || 'nodejs12.x' ,
44
61
Environment : {
45
62
Variables : params . env || { }
46
- }
63
+ } ,
64
+ VpcConfig : vpcConfig
47
65
}
48
66
49
67
await lambda . updateFunctionConfiguration ( updateFunctionConfigurationParams ) . promise ( )
50
68
69
+ // Updates (like vpc changes) need to complete before calling updateFunctionCode
70
+ await lambda . waitFor ( 'functionUpdated' , { FunctionName : params . lambdaName } ) . promise ( )
71
+
51
72
const updateFunctionCodeParams = {
52
73
FunctionName : params . lambdaName , // required
53
74
ZipFile : params . lambdaSrc , // required
@@ -80,7 +101,8 @@ const updateOrCreateLambda = async (aws, params = {}) => {
80
101
Timeout : params . timeout || 300 ,
81
102
Layers : params . layers || [ ] ,
82
103
Runtime : params . runtime || 'nodejs12.x' ,
83
- Publish : params . publish === true ? true : false
104
+ Publish : params . publish === true ? true : false ,
105
+ VpcConfig : vpcConfig
84
106
}
85
107
86
108
const lambdaRes = await lambda . createFunction ( createFunctionParams ) . promise ( )
0 commit comments