Soru

Zorluk: KolayServerless Development with AWS Lambda

A developer is packaging a serverless microservice to run on AWS Lambda. The developer wants to optimize the function's startup performance by reducing cold start latency. Which two actions should the developer take? (Select two.)

  1. Initialize AWS SDK clients and database connection pools outside the handler function to allow reuse across invocationsCevap
  2. Reduce the deployment package size by packaging only the code and dependencies required for executionCevap
  3. C
    Store AWS Access Key ID and Secret Access Key directly within the function's environment variables for client authentication
  4. D
    Set the Amazon SQS queue visibility timeout to be lower than the Lambda function timeout to ensure fast processing
  5. E
    Deploy the Lambda function in a private VPC subnet without an internet route or NAT Gateway to access external APIs

Cevap

Initialize AWS SDK clients and database connection pools outside the handler function, and reduce the deployment package size by packaging only the required code and dependencies.
The correct options represent two standard AWS practices for reducing Lambda latency: utilizing the global execution scope for client initialization to enable context reuse, and minimizing the package size to decrease download and extraction times.

Adım Adım Çözüm

1
Identify the factors that contribute to cold start latency in AWS Lambda.
Cold start duration consists of downloading the deployment package, starting the execution environment container, and running the initialization code (code outside the handler).
Understanding the components of a cold start allows the developer to isolate where optimizations can be made.
2
Evaluate the impact of initialization scope.
By declaring SDK clients and connection pools outside the handler function, they are executed during the initialization phase and reused in subsequent hot invocations.
This takes advantage of execution context reuse, avoiding the overhead of establishing new connections on every function invocation.
3
Evaluate deployment package size optimization.
Excluding unnecessary files, development dependencies, and large unused libraries minimizes the size of the ZIP archive.
AWS Lambda downloads and unpacks smaller deployment packages much faster, directly reducing the container provisioning phase of a cold start.

Anahtar Kavram

AWS Lambda cold start optimization and execution context reuse
Bu soruyu puanla