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.

1 Answer
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
EXPERT
Uri
answered 6 months ago
  • @Uri thanks for your answer. Unfortunately, I tried everything you've mentioned. And I wrote that in my configuration.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions