-
Notifications
You must be signed in to change notification settings - Fork 4.5k
(lambda): vpcSubnets breaking change #21565
Description
Describe the bug
This update introduced a thrown error if the vpcSubnets property is set when the vpc property is not. Although I understand the reasoning of the body:
This is almost certainly never something that a user would intend.
As-is,vpcSubnetsdoes nothing ifvpcis unspecified, so the Lambda
Function would have no interfaces placed in a VPC. This is unlikely to be what
a user would have expected if they passed a set of private subnets. This
should be an error to prevent users from accidentally thinking they've
put a Lambda Function into a VPC.
this broke our pipeline with a patch update. Our use case defaults the vpcSubnet.subnetType value, but uses the vpc property to enforce as documented. At a minimum, can the documentation be changed?
Expected Behavior
Ignore props.vpcSubnets if props.vpc is not specified.
Current Behavior
Respects props.vpcSubnets if props.vpc is not specified
Reproduction Steps
export class Function extends lambda.Function {
constructor(stack: Construct, id: string, props: FunctionProps) {
super(stack, id, {
props.functionName,
timeout: cdk.Duration.seconds(60),
vpc: props.vpcId
? Vpc.fromLookup(stack, `${id}VPC`, {
vpcId: props.vpcId,
})
: undefined,
vpcSubnets: {
subnetType: props.vpcId ? props.subnetType || SubnetType.PRIVATE_WITH_NAT : undefined,
},
...props,
},
});
}
}We depended on props.vpcId as the indicator.
Possible Solution
Remove the Error or update the documentation.
Additional Information/Context
No response
CDK CLI Version
2.37.1
Framework Version
No response
Node.js Version
14.17.4
OS
MacOS
Language
Typescript
Language Version
No response
Other information
No response