DVA-C02 Question 62
Select 2You have created an AWS Lambda function that needs to access a private Amazon RDS database hosted in a VPC. How can you configure the Lambda function to ensure it can communicate with the database?
- A
Configure the Lambda function to connect to the database using its public endpoint.
- B
Attach the Lambda function to the same VPC as the private database and specify the appropriate subnet and security group.
- C
Enable a NAT Gateway in the VPC and configure Lambda to use it for database communication.
- D
Ensure the Lambda function's IAM role has permissions to access VPC resources and the database.
- E
Configure the database's security group to allow inbound traffic from the Lambda function.
Show answer and explanation
Correct answers: B, E
Explanation
To access private resources in a VPC, you must attach your Lambda function to the same VPC by specifying subnets and security groups. Additionally, the database's security group must allow inbound traffic from the Lambda function's security group. These steps ensure proper network-level connectivity between the Lambda function and the private database.
- A. Incorrect.
Incorrect. If the database is in a private subnet, it does not have a public endpoint. This option is not valid for private resources.
- B. Correct.
Correct. Lambda functions can be attached to a VPC by specifying the appropriate subnets and security groups, allowing them to access private resources like the database.
- C. Incorrect.
Incorrect. A NAT Gateway is used to provide internet access to resources in a private subnet, but it is not required for communication between Lambda functions and private databases within the same VPC.
- D. Incorrect.
Incorrect. While the Lambda function's IAM role needs appropriate permissions for other AWS services, it does not directly control network-level access to the private database.
- E. Correct.
Correct. The database's security group must explicitly allow inbound traffic from the Lambda function's security group to establish communication.