Things you need to know about AWS VPC based Lambda

There are two types of AWS Lambda networking settings: No VPC and VPC-based. The major difference is that VPC-based Lambda allows you to access the resources in your VPC, e.g your EC2 resources sitting in the private subnets. No VPC lambda only can access Internet by default.

Before you choose to use VPC-based lambda, there are a couple of things you need to know first:

  1. Do you really need VPC-based Lambda? As I have seen many wrong use cases. Users put Lambda functions in the VPC, which actually only require Internet access. The functions still work as long as the VPC subnets have NAT or Proxy. But it will introduce some cons that will be explained below.
  2. The VPC-based Lambda takes longer time to cold start. The reason is that it will create a ENI which allows the function to access the internal resource through it. Due to the way it works, it brings extra initialisation time.
  3.  Always remember to give the Lambda function the permission to create and delete the ENI, Otherwise you will see lots of invocation errors, it is either caused by it failed to access your internal resources or your account has reached the ENI limit. The best practice is to always have the role ‘AWSLambdaVPCAccessExecutionRole’ included.
  4. Scaling is one of the benefits of using Lambda, as it is all on demand. But be careful with that if you put Lambda function in your VPC, as you may end up reaching your ENI limit quickly if you have relatively small subnets and high function invocations. The consequence is that other resources in the same subnet won’t be able to scale up either, like ELB or Autoscaling group.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s