A developer is building a serverless order-processing application. An AWS Lambda function is triggered by an Amazon SQS queue. The function must connect to an Amazon RDS PostgreSQL database located in a private VPC subnet to retrieve customer data, and call a third-party payment gateway API over the internet to authorize transactions. The developer also wants to minimize connection latency to the database. Which combination of configurations must the developer implement to meet these requirements? (Select two.)
- Deploy the Lambda function in the private subnets of the VPC and configure a NAT Gateway in a public subnet with appropriate route tables to allow outbound internet traffic.Cevap
- Instantiate the database client connection pool outside of the Lambda handler function.Cevap
- CDeploy the Lambda function in the public subnets of the VPC to grant it direct access to the internet and the RDS database.
- DRe-establish a new database connection inside the Lambda handler function for every incoming event.
- EHardcode the database credentials and payment gateway API key directly in the Lambda function's source code.
Cevap
To meet the requirements, the developer must deploy the Lambda function in private subnets using a NAT Gateway in a public subnet for outbound internet connectivity, and instantiate the database connection client outside of the handler function to reuse connections.
Deploying the Lambda function in private subnets with a NAT Gateway in the public subnet allows both outbound internet access for API calls and secure local access to the private RDS database. Initializing the database connection pool outside the handler ensures that the connections are reused across events due to execution context recycling, optimizing latency.
Adım Adım Çözüm
Anahtar Kavram
AWS Lambda VPC networking and execution context reuse