How can I connect DocumentDB Change Stream as a Trigger Source of Lambda Function in Private VPC?

0

I'm following this tutorial: https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb-tutorial.html And I found it won't work if I change the VPC settings to a custom VPC with private subnets. I'm stuck with this message in the Lambda Function's Source Trigger:

PROBLEM: Connection error. Your VPC must be able to connect to Lambda and STS, as well as Secrets Manager if authentication is required. You can provide access by configuring PrivateLink or a NAT Gateway.

My use-case is simple. Trigger the Lambda Function by the Change Stream, and write logs(for now, that's enough) in the private subnets. There's no reason to access or to be accessed to/from the public, except Amazon Services itself(Lambda, DocumentDB, SecretsManager, etc...)

Here's my configurations:

  1. VPC
  • A new VPC
  • has two subnets
  • all other resources live on private subnets
  • private subnets connected with NAT Gateway as well (actually it doesn't seem to be necessary, but just in case)
  • also have VPC EndPoints for S3, Lambda, SecretsManager, and even ec2messages and STS Enter image description here
  1. DocumentDB
  • created with a subnet group that contains only the private subnets in the VPC above
  • enabled change stream as well
  • a security group that opens all port and source/destination because I failed to connect every attempt. It's really a bummer.
  1. Lambda Function
  • created in the same private subnets in the VPC
  • a security group that opens all port and source/destination
  • same source code in the tutorial

It's really difficult to get what's the real problem with the Lambda Function. I hope somebody provides a clean tutorial that works in the private subnets of the custom VPC, not the default one. Thanks.

gongdo
已提問 7 個月前檢視次數 517 次
1 個回答
1

Based on the error message you either need to create a NAT Gateway in the VPC, with the appropriate route to the internet via the GW, or create VPC endpoints to Lambda, STS and Secrets Manager. It seems the integration with Document DB needs to access these services from within the VPC.

profile pictureAWS
專家
Uri
已回答 7 個月前
  • @Uri thanks for your answer. Unfortunately, I tried everything you've mentioned. And I wrote that in my configuration.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南