fix(lambda): Function allows specifying vpcSubnets without vpc#21369
fix(lambda): Function allows specifying vpcSubnets without vpc#21369mergify[bot] merged 8 commits intoaws:mainfrom
Conversation
50d0061 to
ad050ac
Compare
This is almost certainly never something that a user would intend. As-is, `vpcSubnets` does nothing if `vpc` is unspecified, so the Lambda Function would have no interfaces placed in a VPC. This is unlikely 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. If throwing an Error is a breaking change and not acceptable, then perhaps at least a Warning Annotation should be added in this case.
ad050ac to
6e52f64
Compare
| if (props.vpc) { | ||
| // Policy that will have ENI creation permissions | ||
| managedPolicies.push(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaVPCAccessExecutionRole')); | ||
| } else if (props.vpcSubnets) { |
There was a problem hiding this comment.
I think I'm fine with this change given that it does not cause any changes to the deployed infra.
One nit - can you put this check in the configureVpc method? It feels like it should go there since that is where the other checks are.
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
Just a couple of stylistic suggestions.
| if (!props.vpc) { | ||
| if (props.vpcSubnets) { |
There was a problem hiding this comment.
| if (!props.vpc) { | |
| if (props.vpcSubnets) { | |
| if (!props.vpc && props.vpcSubnets) { |
There was a problem hiding this comment.
I thought about doing this, but there's the return undefined; after the inner if. So it'd have to be rewritten as:
if (!props.vpc && props.vpcSubnets) {
throw new Error("...");
} else if (!props.vpc) {
return undefined
}which felt a little messy and maybe more confusing to repeat half of the condition?
Actually mean to include a note/question about this when I pushed the new commit but got distracted by the failing build 😄 So I'm happy to making the change but just want to make sure that this is the desired outcome?
There was a problem hiding this comment.
No need for you to revise because of a small stylistic difference. I only made the suggestion because I was also making the suggestion to change the error message. Otherwise, I would have just plain approved since @corymhall is also in favor.
There was a problem hiding this comment.
But also, I didn't notice that the error message above was infinitely better than the one I suggested. So, sorry, one more suggested change to that.
There was a problem hiding this comment.
All good! And I meant "meant to" instead of "mean to" -- oops, sorta changes the tone. But in any case, thanks for the feedback on the error message. I read https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md#error-messages and I think ended up writing something too wordy; this one is much clearer!
Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
Pull request has been modified.
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
I should have looked at the code directly above and made my suggestion to align to that. Sorry for the extra back and forth!
| if (!props.vpc) { | ||
| if (props.vpcSubnets) { |
There was a problem hiding this comment.
But also, I didn't notice that the error message above was infinitely better than the one I suggested. So, sorry, one more suggested change to that.
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
Aaand then I hit the wrong button...
Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
Pull request has been modified.
|
Not sure what's up with the CodeBuild failure this time around -- it doesn't really feel related to anything that's changed and running the |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Recently, the Function construct was changed to raise an error if `vpcSubnets` was specified but `vpc` wasn't; however, this change was not properly reflected in the documentation for the function. The change itself was made in #21369. Closes #21565 ---- ### All Submissions: * [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This is almost certainly never something that a user would intend.
As-is,
vpcSubnetsdoes nothing ifvpcis unspecified, so the LambdaFunction 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.
If throwing an Error is a breaking change and not acceptable, then
perhaps at least a Warning Annotation should be added in this case.
This is motivated by the feedback received during review of #21357.
All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integto deploy the infrastructure and generate the snapshot (i.e.yarn integwithout--dry-run)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license