AWS Bites Podcast

84. Are VPCs an anti-pattern?

In this episode of AWS Bites, we explore the future of Virtual Private Clouds (VPCs) in the context of the zero-trust security trend.

We'll dive into the pros and cons of using VPCs, including their usefulness when dealing with sensitive data or when you need fine-grained control over your network environment. But let's be real, sometimes VPCs can be a bit of a headache. We'll discuss why you might want to avoid them, including the added complexity they can bring to your network environment.

Fear not, we'll also provide a summary of when to use and when not to use VPCs, as well as alternatives to using VPCs, such as services that don't require them.

So, are ready to talk VPCs!?

AWS Bites is sponsored by fourTheorem, an AWS Consulting Partner offering training, cloud migration, and modern application architecture.

In this episode, we mentioned the following resources:

Let's talk!

Do you agree with our opinions? Do you have interesting AWS questions you'd like us to chat about? Leave a comment on YouTube or connect with us on:

00:05:33

That's an optional configuration, which will give them access to resources inside that VPC, such as a database or some other services. So in general, VPCs and serverless applications can be used for a few different use cases. So we mentioned accessing resources in a VPC or in an on-premises network. Another one is preventing outbound internet access to prevent data exfiltration in the event of a vulnerability. So you can imagine if there's a supply chain attack and one of your modules is kind of rogue or has a vulnerability and an attacker gets access to that environment, they might need to exfiltrate some keys or some data. If they don't have internet access, you're making it very difficult for them to do that. So having a network boundary on top of your zero trust mechanism makes it, it just gives you more defense in depth there. Of course, from a compliance point of view, or just like a really strict, well thought through network architecture, you might want to do traffic analysis. And if it's all on AWS's managed network, you can't do that. But if everything is in a VPC, you can use things like VPC flow logs to monitor your traffic. And then you can also get fine-grained access control over access to AWS services with routing, security groups, and VPC endpoints as well, which can have their own policies. Finally, I'd say service discovery through private DNS is another thing you can get if you have VPCs. So if you've got a hybrid of instances, containers, and things like Lambda functions, it might make sense to think about service discovery and DNS as well. So there's still some valid cases for thinking about VPCs. I wouldn't dismiss them just yet, but it's not necessarily, you would have to think through the trade-offs and think if you could have avoided VPCs until now, you might think, okay, should I go and start creating network resources just because I need a database? Or should I continue to try and use serverless options where I don't have to think about networking? So why would you avoid VPCs, Luciano?

00:09:21

The other thing is that you might be wanting to provision bastion hosts or VPNs. Again, because if you start to have things behind, basically in a private network, in a way that they are not very easy to access. Sometimes if you want to access from your own laptop, because you are trying to debug something, maybe access another base, for instance, or Redis, you need to figure out how do I do that? How do I enable that? And again, that requires provisioning more infrastructure and thinking more about security. And you are potentially creating a backdoor that is useful to yourself. But if you don't make it secure enough, you are actually creating a security risk there. We actually have been speaking about some of these topics, specifically around the concept of bastion hosts in another episode. So we'll have the link in the show notes if you're curious to explore that topic as well. And again, monitoring and intrusion detection. It's something you probably want to do. You want to have ways to understand what's happening in that VPC. And if somebody is having access and that somebody is not supposed to do that, how do you spot that and how do you react to that? You need to put all these kinds of things in place somehow. So again, I think that just to boil it down is not an easy feat. It's something you need to spend a significant amount of time learning, trying things before you can feel confident that you are doing it correctly and you can go to production without any big surprise. So I suppose if all of that sounds scary enough, how realistic it is that you just go VPC-less and be able to deploy even significantly complicated application without having to think about VPCs. Is that actually possible today or not? Yeah, definitely possible.

Luciano
00:12:54

I wouldn't say, at least in the context of serverless, that VPCs are an anti-pattern. As you said, it's something that you can avoid in many situations. But I think there are situations where if you weight the benefits and the complexity, there might be a trade-off there where it could be worth it doing serverless and also do VPCs. And just to give you some examples, very simply, probably a use case we've been talking about before is if you start to use RDS, that's kind of a service that forces you to go down the path of creating your own VPCs. And then if you want to connect a Lambda, for instance, to your own RDS database, the easiest way is probably to just put the Lambda in the same VPC where you have your own database and make sure that the whole routing and subnets is configured correctly so that you can have access from the Lambda directory to the database. And very similarly, if you use ECS or EKS or Elasticash or Kafka or OpenSearch, all these services are built around the concept you need to effectively provision instances behind the scenes in a specific VPC. So you need to think about how am I going to structure this VPC and how I'm going to connect things together. So this is definitely a very good case where if you use some of these services, you are a bit forced down the path of thinking about VPCs. But again, as you said before, it's not necessarily a bad thing because you gain additional control in the sense of being able to add more in-depth security. So you can add more things around your application that makes it a little bit more secure. So it might not be just extra work for you. It gives you some advantages as well. In summary, I will say that VPCs are not necessarily an anti-pattern, but it's just something that you might or might not need to use. And if you need to use, of course, you need to be careful in terms of just not discount the amount of work and the amount of complexity that there is and make sure you take enough time to absorb all the concept and to try different things and to test that you're set up is actually doing what you think it needs to be doing. So again, anything that you would add in terms of how to think about VPCs in the context of Lambda?

Eoin
00:15:11

Well, if you want to access resources in VPC or in an on-premises network, you need to define VPC subnets and security groups for the Lambda function. It's actually interesting with security groups and Lambda function, it can be a little bit misleading because normally with security groups, you can say what ports are allowed in, what ports are allowed out, but Lambda doesn't really work like that because it doesn't have that stateful socket connection. So the only reason you define security groups really with Lambda is that so you can use those security groups in the rules of other security groups and allow that Lambda function to access network resources. The VPC with Lambda used to make a massive difference for cold start times. So Lambda used to create and attach an elastic network interface or an ENI for the cold start of each container. I think that was what led to the problem you mentioned having experienced when your IP CIDR block was too small. But this is no longer the case. So in the end of 2019, AWS changed this. So an ENI is now provisioned for the function when you deploy it and each Lambda container routes through this interface using a VPC to VPC NAT instead. So it's much more efficient. It doesn't impact cold start times like it used to and just makes VPCs with Lambda way more useful than they used to be. So that's what it used to be. So there are some advantages then of using VPCs for Lambda that are really worthwhile to state. And I think one really interesting one is something we alluded to earlier. You can prevent outbound internet access. There's no other way to do this.

00:16:31

There used to be this product called Function Shield, which doesn't really exist anymore, which was like a low level interface that would try and prevent outbound internet access to prevent exfiltration. But the only way to do this really now effectively is with a VPC and ensuring that there's no route to the internet from that VPC. So it's a useful security perimeter then. And if you've got that supply chain attack problem, you don't have to worry as much. You can also then analyze traffic with VPC flow logs and you've got fine grain network control, right? So in a corporate environment or if you've got other network resources, it can make a lot of sense to use Lambda with VPC. Now I would still in a lot of cases, even when you've got a corporate environment end up with a hybrid approach where you've got lots of Lambda functions that don't need to access those network resources. So those ones don't get assigned a subnet. And then the ones that do, do get to assign a subnet. So you can mix it like that. So I would definitely think, okay, don't worry so much about VPCs for Lambda. If you've got VPCs and private networks, it makes sense to just start using it. And we've got plenty of very serverless applications out there now that use ElastiCache and RDS and other VPC connected resources. And it's just becomes part of the architecture that you have to use VPCs at least until we get into a situation where maybe AWS will start to think about more of a zero trust model for all services. Like with RDS, you've got the data API now, maybe in the future, we'll have other examples where you're just using more like HTTP based interaction for all of these services using IAM instead of network controls. I'm going to try to do a summary of everything we just said today.

Help us to make this transcription better! If you find an error, please submit a PR with your corrections.