Skip to content

fix(lambda): Function allows specifying vpcSubnets without vpc#21369

Merged
mergify[bot] merged 8 commits intoaws:mainfrom
laurelmay:add-warning-on-vpcsubnets-without-vpc
Aug 4, 2022
Merged

fix(lambda): Function allows specifying vpcSubnets without vpc#21369
mergify[bot] merged 8 commits intoaws:mainfrom
laurelmay:add-warning-on-vpcsubnets-without-vpc

Conversation

@laurelmay
Copy link
Copy Markdown
Contributor

@laurelmay laurelmay commented Jul 29, 2022

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 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:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • 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

@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jul 29, 2022

@github-actions github-actions bot added the p2 label Jul 29, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team July 29, 2022 02:22
@laurelmay laurelmay force-pushed the add-warning-on-vpcsubnets-without-vpc branch from 50d0061 to ad050ac Compare July 29, 2022 02:55
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.
@laurelmay laurelmay force-pushed the add-warning-on-vpcsubnets-without-vpc branch from ad050ac to 6e52f64 Compare July 29, 2022 03:08
if (props.vpc) {
// Policy that will have ENI creation permissions
managedPolicies.push(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaVPCAccessExecutionRole'));
} else if (props.vpcSubnets) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mergify mergify bot dismissed corymhall’s stale review August 3, 2022 23:31

Pull request has been modified.

@laurelmay
Copy link
Copy Markdown
Contributor Author

Hoping the failure on ec5cd4f is fixed by #21374 and therefore the merge from main.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of stylistic suggestions.

Comment on lines +1097 to +1098
if (!props.vpc) {
if (props.vpcSubnets) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!props.vpc) {
if (props.vpcSubnets) {
if (!props.vpc && props.vpcSubnets) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review August 4, 2022 01:55

Pull request has been modified.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have looked at the code directly above and made my suggestion to align to that. Sorry for the extra back and forth!

Comment on lines +1097 to +1098
if (!props.vpc) {
if (props.vpcSubnets) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TheRealAmazonKendra added the pr/do-not-merge This PR should not be merged at this time. label Aug 4, 2022
Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaand then I hit the wrong button...

@TheRealAmazonKendra TheRealAmazonKendra removed the pr/do-not-merge This PR should not be merged at this time. label Aug 4, 2022
Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review August 4, 2022 11:47

Pull request has been modified.

@laurelmay
Copy link
Copy Markdown
Contributor Author

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 integ-runner tests locally doesn't result in a failure. I think I'm just going to hope it's a one-off issue and that re-triggering a build fixes it? But I don't know how to ask CodeBuild to rebuild without a new commit so I'll just click the Update branch button? 🤷🏻

@aws-cdk/integ-runner: FAIL test/runner/snapshot-test-runner.test.js
@aws-cdk/integ-runner:   ● IntegTest runSnapshotTests › with defaults no diff
@aws-cdk/integ-runner:     Cannot read integ manifest 'test/test-data/test-with-snapshot.integ.snapshot/manifest.json': Unexpected end of JSON input
@aws-cdk/integ-runner:       32 |
@aws-cdk/integ-runner:       33 |     } catch (e) {
@aws-cdk/integ-runner:     > 34 |       throw new Error(`Cannot read integ manifest '${fileName}': ${e.message}`);
@aws-cdk/integ-runner:          |             ^
@aws-cdk/integ-runner:       35 |     }
@aws-cdk/integ-runner:       36 |   }
@aws-cdk/integ-runner:       37 |
@aws-cdk/integ-runner:       at Function.fromFile (lib/runner/private/cloud-assembly.ts:34:13)
@aws-cdk/integ-runner:       at Function.fromPath (lib/runner/private/cloud-assembly.ts:51:37)
@aws-cdk/integ-runner:       at IntegSnapshotRunner.readAssembly (lib/runner/snapshot-test-runner.ts:223:45)
@aws-cdk/integ-runner:       at IntegSnapshotRunner.testSnapshot (lib/runner/snapshot-test-runner.ts:55:33)
@aws-cdk/integ-runner:       at Object.<anonymous> (test/runner/snapshot-test-runner.test.ts:55:31)

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Aug 4, 2022

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-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 6512acb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit e9233fa into aws:main Aug 4, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Aug 4, 2022

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).

@laurelmay laurelmay deleted the add-warning-on-vpcsubnets-without-vpc branch August 4, 2022 15:35
laurelmay added a commit to laurelmay/aws-cdk that referenced this pull request Aug 12, 2022
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 aws#21369.

Closes aws#21565
mergify bot pushed a commit that referenced this pull request Aug 12, 2022
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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants