How to configure a Lambda function to access resources in a VPC

+1 vote

Hi Guys,

When building an application with AWS Lambda, I need to host my Lambda function in a VPC. The reason for this is because the Lambda function will use other resources that aren’t accessible from the public internet, such as a relational database or Redis instance. But how can I do that, can anyone suggest?

Aug 27, 2020 in AWS by akhtar
• 38,230 points

1 answer to this question.

0 votes


You can configure a Lambda function to connect to private subnets in a virtual private cloud (VPC) in your AWS account. Use Amazon Virtual Private Cloud (Amazon VPC) to create a private network for resources such as databases, cache instances, or internal services. Connect your function to the VPC to access private resources during execution.

To connect a function to a VPC

  1. Open the Lambda console Functions page.

  2. Choose a function.

  3. Under VPC, choose Edit.

  4. For VPC connection, choose Custom VPC.

  5. Choose a VPC, subnets, and security groups.

  6. Choose Save.

When you connect a function to a VPC, Lambda creates an elastic network interface for each combination of the security group and subnet in your function's VPC configuration. This process can take about a minute.

answered Aug 27, 2020 by MD
• 95,440 points

Related Questions In AWS

0 votes
1 answer

how to access AWS S3 from Lambda in VPC

With boto3, the S3 urls are virtual by default, ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 58,090 points
0 votes
2 answers

How to kill a lambda function in AWS?

$ aws lambda put-function-concurrency --function-name my-function --reserved-concurrent-executions ...READ MORE

answered Mar 28, 2019 in AWS by Shashank
• 1,370 points
+1 vote
1 answer
0 votes
1 answer

How to create subnets in a vpc using boto3?

Here is the simple way of implementing ...READ MORE

answered Dec 5, 2018 in AWS by Shuvodip Ghosh
0 votes
1 answer
0 votes
1 answer
+2 votes
3 answers
0 votes
3 answers

How to check instance state and status via Lambda function in AWS?

import boto3 from pprint import pprint def lambda_handler(event, context):          # ...READ MORE

answered Sep 8, 2020 in AWS by Shrikant
• 180 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP