Skip to content

Commit f2d1e23

Browse files
fix(AWS Deploy): Ensure vpc configuration on custom resources (serverless#11985)
1 parent 3afb71e commit f2d1e23

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/plugins/aws/custom-resources/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ async function addCustomResourceToService(awsProvider, resourceName, iamRoleStat
179179
};
180180
Resources[customResourceFunctionLogicalId] = customResourceFunction;
181181

182+
if (providerConfig.vpc && providerConfig.vpc.securityGroupIds && providerConfig.vpc.subnetIds) {
183+
customResourceFunction.Properties.VpcConfig = {
184+
SecurityGroupIds: providerConfig.vpc.securityGroupIds,
185+
SubnetIds: providerConfig.vpc.subnetIds,
186+
};
187+
}
188+
182189
if (customDeploymentRole) {
183190
customResourceFunction.Properties.Role = customDeploymentRole;
184191
} else {

test/unit/lib/plugins/aws/custom-resources/index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,33 @@ describe('#addCustomResourceToService()', () => {
347347
Resources.CustomDashresourceDashexistingDashs3LambdaFunction.Properties.FunctionName.length
348348
).to.be.below(65);
349349
});
350+
351+
it('should configure vpc configs for the custom resource lambda function if vpc is configured', async () => {
352+
const vpcConfig = {
353+
securityGroupIds: ['sg-0a0a0a0a'],
354+
subnetIds: ['subnet-01010101'],
355+
};
356+
const { cfTemplate } = await runServerless({
357+
fixture: 'api-gateway',
358+
command: 'package',
359+
configExt: {
360+
provider: {
361+
logs: {
362+
restApi: true,
363+
},
364+
vpc: vpcConfig,
365+
},
366+
},
367+
});
368+
369+
const properties =
370+
cfTemplate.Resources.CustomDashresourceDashapigwDashcwDashroleLambdaFunction.Properties;
371+
372+
expect(properties.VpcConfig).to.deep.equal({
373+
SecurityGroupIds: ['sg-0a0a0a0a'],
374+
SubnetIds: ['subnet-01010101'],
375+
});
376+
});
350377
});
351378

352379
describe('test/unit/lib/plugins/aws/customResources/index.test.js', () => {

0 commit comments

Comments
 (0)