-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lambda): cannot create lambda in public subnets #9468
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these changes. The main set of code changes look good.
Some comments below around messaging, documentation and tests.
if (publicSubnetIds.has(subnetId)) { | ||
throw new Error('Not possible to place Lambda Functions in a Public subnet'); | ||
if (publicSubnetIds.has(subnetId) && !allowPublicSubnet) { | ||
throw new Error('Lambda Functions in a Public subnet won\'t have internet access. If you need to do this, set `allowPublicSubnet` to true'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error('Lambda Functions in a Public subnet won\'t have internet access. If you need to do this, set `allowPublicSubnet` to true'); | |
throw new Error('Lambda Functions in a public subnet can NOT access the internet. ' + | |
'If you are aware of this limitation and would still like to place the function int a public subnet, set `allowPublicSubnet` to true'); |
* Whether to override the error when trying to place a Function into a public subnet. Lambda functions in Public | ||
* subnets cannot access the internet, so only do this if you need to. | ||
* | ||
* @default - false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Whether to override the error when trying to place a Function into a public subnet. Lambda functions in Public | |
* subnets cannot access the internet, so only do this if you need to. | |
* | |
* @default - false | |
* Lambda Functions in a public subnet can NOT access the internet. | |
* Use this property to acknowledge this limitation and still place the function in a public subnet. | |
* @see https://stackoverflow.com/questions/52992085/why-cant-an-aws-lambda-function-inside-a-public-subnet-in-a-vpc-connect-to-the/52994841#52994841 | |
* | |
* @default false |
test.done(); | ||
}, | ||
|
||
'picking public subnet type is not allowed if not overriding allowPublicSubnet'(test: Test) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'picking public subnet type is not allowed if not overriding allowPublicSubnet'(test: Test) { | |
'picking public subnet type is not allowed by default'(test: Test) { |
vpc, | ||
vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the error is the one that we actually expect, and not some other validation/error.
}); | |
}, /Lambda Functions in a public subnet/); |
test.doesNotThrow(() => { | ||
new lambda.Function(stack, 'PrivateLambda', { | ||
code: new lambda.InlineCode('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
vpc, | ||
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE }, | ||
}); | ||
}); | ||
|
||
test.doesNotThrow(() => { | ||
new lambda.Function(stack, 'IsolatedLambda', { | ||
code: new lambda.InlineCode('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
vpc, | ||
vpcSubnets: { subnetType: ec2.SubnetType.ISOLATED }, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions should be replaced with assertions that the CloudFormation template is correctly configured.
This will probably need to be split into separate tests for each subnet type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions should be replaced with assertions that the CloudFormation template is correctly configured.
You mean like a hasResourceLike
assertion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Thank you for contributing! Your pull request will be updated from master 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 master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
…10022) Fixes #10018. Fixes #10027. #9468 added a flag (`allowPublicSubnet`) to `FunctionProps`, but `PythonFunction` and `NodejsFunction` props derive from `FunctionOptions`. This renders these derived function constructs unable to bypass the public subnet check that occurs in the base `Function` construct. We can resolve this issue by moving `allowPublicSubnet` to `FunctionOptions`. I also moved `filesystem` up to `FunctionOptions` while I was here. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Closes #8935
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license