Soru

Zorluk: ZorServerless Development with AWS Lambda

A company is migrating a transaction processing system to AWS. The solution uses an AWS Lambda function that must process events from an Amazon SQS queue, perform a call to an external payment gateway API over the public internet, and save the transaction status to an Amazon DynamoDB table. The Lambda function is configured to run inside private subnets of an Amazon VPC to comply with security requirements. During testing, the function experiences connection timeout errors when trying to reach the payment gateway. Additionally, many SQS messages are being processed multiple times by different Lambda invocations. Which two configuration changes should a developer make to resolve these issues? (Select two.)

  1. Configure a NAT Gateway in a public subnet of the VPC, and add a route in the private subnet's route table directing outbound destination 0.0.0.0/0 traffic to the NAT Gateway.Cevap
  2. Increase the visibility timeout of the Amazon SQS queue to at least 6 times the timeout of the Lambda function.Cevap
  3. C
    Attach an Internet Gateway directly to the private subnet where the Lambda function resides, and modify the route table to route 0.0.0.0/0 traffic to it.
  4. D
    Set the visibility timeout of the Amazon SQS queue to be equal to or less than the Lambda function timeout to ensure that messages return to the queue immediately if the function fails.
  5. E
    Associate an Elastic IP address directly to the Lambda function's elastic network interface (ENI) to allow direct outbound communication with the external API.

Cevap

To resolve the issues, configure a NAT Gateway in a public subnet of the VPC and route outbound destination 0.0.0.0/0 traffic from the private subnet's route table to the NAT Gateway, and increase the visibility timeout of the Amazon SQS queue to at least 6 times the timeout of the Lambda function.
Configuring a NAT Gateway in a public subnet and routing the private subnet's outbound traffic (0.0.0.0/0) to it enables the Lambda function inside the private subnet to securely access the public internet (external payment gateway). Concurrently, setting the Amazon SQS visibility timeout to at least 6 times the Lambda function timeout satisfies the AWS-recommended integration guidelines, preventing messages from being visible to other pollers before the current invocation completes or has a chance to retry.

Adım Adım Çözüm

1
Analyze the connection timeout issue for the VPC-attached Lambda function trying to reach the public internet.
Identify that a Lambda function attached to a private subnet of a VPC does not have public internet access by default. It requires routing public-destined traffic through a NAT Gateway situated in a public subnet.
Since the payment gateway is on the public internet, outbound network translation is required for private subnet resources.
2
Analyze the duplicate message processing issue for the SQS queue integrated with Lambda.
Determine that if the SQS visibility timeout is not sufficiently longer than the Lambda function's timeout, messages will reappear in the queue before the processing invocation completes, leading to duplicate invocations.
AWS best practices specify that the queue's visibility timeout should be set to at least 6 times the function timeout to prevent early message visibility and allow for proper retries.
3
Select the two correct configuration steps matching the findings.
Select the configuration of a NAT Gateway with appropriate private subnet routing and adjusting the SQS visibility timeout to at least 6 times the Lambda timeout.
These steps address the specific causes of the connection timeouts and the duplicate processing errors.

Anahtar Kavram

Configuring VPC routing for outbound access in AWS Lambda and adjusting SQS queue visibility timeout relative to Lambda timeouts.
Bu soruyu puanla