Question

Difficulty: Very hardVPC Security for Developers

A developer is implementing an AWS Lambda function that must query an Amazon Aurora PostgreSQL database located in a private VPC subnet. Additionally, the Lambda function must retrieve database credentials from AWS Secrets Manager and send HTTP POST requests to an external API endpoint over the public internet.

Which network and security configuration should the developer implement to meet these requirements securely while adhering to the principle of least privilege?

  1. Deploy the Lambda function in the private subnets. Associate a security group with the Lambda function that allows outbound TCP traffic on port 54325432 to the database security group and outbound HTTPS traffic on port 443443. Configure the private subnets' route table to route 0.0.0.0/00.0.0.0/0 traffic to a NAT Gateway located in a public subnet. Configure the database security group to allow inbound traffic on port 54325432 only from the Lambda function's security group.Answer
  2. B
    Deploy the Lambda function in the private subnets. Associate a security group with the Lambda function that allows outbound TCP traffic on port 54325432 to the database security group and outbound HTTPS traffic on port 443443. Configure the private subnets' route table to route 0.0.0.0/00.0.0.0/0 traffic directly to the Internet Gateway. Configure the database security group to allow inbound traffic on port 54325432 only from the Lambda function's security group.
  3. C
    Deploy the Lambda function in the public subnets to ensure it has native internet access to reach Secrets Manager and the external API. Store the database credentials in Systems Manager Parameter Store as a standard String parameter. Configure the database security group to allow inbound traffic on port 54325432 from the public subnet CIDR blocks.
  4. D
    Deploy the Lambda function in the private subnets. Configure the database security group to allow inbound traffic on port 54325432 from 0.0.0.0/00.0.0.0/0. Attach an IAM policy to the Lambda execution role that allows the `sts:AssumeRole` action on the database, and modify the database's IAM trust policy to trust the Lambda function's execution role.

Answer

Deploy the Lambda function in the private subnets, configure a NAT Gateway in a public subnet to route 0.0.0.0/00.0.0.0/0 traffic, and associate a security group with the Aurora database that allows inbound traffic on port 54325432 only from the Lambda security group.
The correct network configuration places both the Lambda function and the database in private subnets. Outbound internet access for the Lambda function (to access the external payment gateway and public Secrets Manager endpoints) is enabled by routing 0.0.0.0/00.0.0.0/0 traffic through a NAT Gateway in a public subnet. Database access is securely restricted at the network layer by configuring the database's security group to allow inbound connections on port 54325432 only from the Lambda function's security group.

Step-by-Step Solution

1
Determine the placement of the Lambda function and the database.
Both resources are placed inside private VPC subnets to isolate them from direct public internet exposure.
This is required to protect the database and application layer in accordance with the AWS Well-Architected Framework.
2
Provide outbound internet connectivity for the Lambda function.
Route the private subnets' 0.0.0.0/00.0.0.0/0 traffic to a NAT Gateway situated in a public subnet.
The Lambda function needs internet access to communicate with the external API and public endpoints for Secrets Manager, but it lacks public IP addresses itself.
3
Configure the security groups for secure, localized communication.
Allow outbound port 54325432 and port 443443 traffic on the Lambda security group, and configure the database security group to allow inbound port 54325432 traffic only when originating from the Lambda security group.
This implements the principle of least privilege by strictly restricting database access to the Lambda function at the network layer.

Key Concept

AWS Lambda VPC networking, Security Group referencing, and NAT Gateway routing for private-to-public subnet communication.
Rate this question