[RFC] VPC #66
Replies: 2 comments 2 replies
-
Thanks for opening this, continuing our Slack discussion here. As you mention, we have 2 scenarios:
I'll be opening a separate discussion to see how we address this, as we'll get the same challenge with other constructs (e.g. RDS database). In the meantime, I suggest we focus on the production use case for now. For the record we discussed VPC config separately with Marco and came to the conclusion that for production scenarios, it would make sense to go by default with:
I don't think we want to provide an option to use NAT instances for the production version (at least at first). As for any extra feature (bastion, etc.) those are great ideas, but I would start without them at first TBH.
Oh that's too bad. I think it is tracked by this bug report: aws/aws-cdk#6015 I'm fine with documenting that at first. Maybe if there are only a few problematic regions we could add an error message/warning in the code itself? |
Beta Was this translation helpful? Give feedback.
-
Opening a separate thread for "should it be a construct?" We initially planned the VPC to be "hidden": it would be created/enabled as soon as you would import a construct that requires it. E.g. if you use a And to be clear: it would automatically apply to all functions. Not having it as a classic construct solves the issue of "you can't have 2 VPC constructs". However, we still need to put it in the YAML file somewhere. One possibility could be: service: myapp
provider:
lift:
vpc:
az: 3 # optional setting Any other idea? (also ping @fredericbarthelet) |
Beta Was this translation helpful? Give feedback.
-
The goal of this discussion is to get feedback on a potential "VPC" construct.
The current implementation is setting the VPC config on all functions in the stack.
The idea would be to build this as a foundation for other constructs that need Lambda functions to be in a VPC such as
I think a good start would be to be on par with the main features provided by serverless-vpc-plugin.
Quick start
How it works
The basis of this is the awesome L2 VPC Construct provided by the CDK.
The defaults of the construct are generally what you want:
But this setup has a significant cost mainly because of the NAT gateways, so that's why it's important to be able to configure it for less critical apps or dev/staging environments.
Configuration reference
Configuring NAT Gateways
We have two options here :
natGateways
which determines the number of gateways to provision. If not set or set to a high number, this will provision as many NAT as there are AZs in the regionnatGatewayType
can be eithergateway
which will provision the fully managed NAT Gateway from AWS; orinstance
which will provision a smallt3.nano
NAT InstanceUsed together, they can help people save hundreds of dollars on dev/test environments with this kind of config
There are of course more options to consider : maximum number of AZs to use, maybe bastion hosts or use Session Manager to do it and provide a Lift command to connect, and many more !
Challenges
I see several challenges to this.
Should we allow to specifiy which functions have to be in the generated VPC ? Or apply it to all functions ? If we choose the later, this construct can only be used once in a given app.
How to get the maximum number of AZs right ? The CDK is supposedly able to guess this from the region and account ID, but my tests were not conclusive about this. This causes problems because
us-west-1
has 3 AZs but you only get access to 2 of them by default (you can check that by runningaws ec2 describe-availability-zones --region=us-west-1
with credentials/profiles configured).If Lift generated subnets in the 3 AZs, the deployment would fail. This can be documented but maybe there's a better approach.
How to make the other (future) constructs "auto-discover" the VPC and use its configuration to generate required resources like Subnet groups.
Draft Pull Request
See a draft implementation here #65
Would love to get your feedback about this
Beta Was this translation helpful? Give feedback.
All reactions