Connect a Lambda function to an S3 bucket while being connected to a VPC to make queries to a private RDS.

0

I'm creating a Lambda function that receives parameters in a POST request, including an object (CSV file) that I need to access and execute a series of queries based on its content to a private RDS.

I can access the S3 bucket if the Lambda function is not associated with a VPC, but in this case, I cannot access the private RDS. Also I have reviewed the security groups, route tables, and there is an internet gateway. I have also checked the IAM policies, which allow listing and reading from any bucket.

2개 답변
3
수락된 답변

This is very common scenario as same applicable for all compute. As a best practice you should create Lambda within VPC so you can access RDS. To access S3 from Lambda function inside a VPC, use VPC endpoints

profile pictureAWS
Nirmal
답변함 일 년 전
profile picture
전문가
검토됨 한 달 전
  • And or have your Lambda function connect to a subnet with a route to a NAT gateway to provide internet connectivity so that you can reach services such as S3.

    However, I do agree with Nirmal. Create VPC Endpoints. I believe a S3 gateway endpoint is free. Make sure you have a route with the preflix list applied to the subnet where your Lambda function connects

  • Thanks to all. I follow the advice and create the endpoint and works properly.

1

You must connect the Lambda to a VPC that can communicate with the database or look at other options, such as RDS Proxy or the RDS Data API. I haven't used RDS Proxy or RDS's Data API recently, and I can't remember if they enable communication with the DB without being in the private VPC, but that is where I would look first.

profile picture
답변함 일 년 전
  • Thanks for the advice, I made the endpoint first and it works, perhaps in another time I can try the proxy.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠