Soru

Zorluk: OrtaServerless Development with AWS Lambda

A developer is designing an AWS Lambda function that processes incoming images. The function requires a static machine learning model file of 250 MB250\text{ MB}, which is stored in a private Amazon S3 bucket. This model file is read-only and rarely updated. To process the images, the function also needs to write metadata to an Amazon DynamoDB table. The developer wants to optimize the Lambda function's performance by minimizing execution time and avoiding unnecessary API calls during cold starts and warm invocations. Which of the following actions should the developer take to meet these requirements? (Select TWO.)

  1. Initialize the Amazon S3 and Amazon DynamoDB SDK client objects outside of the Lambda handler function.Cevap
  2. Download the model file to the `/tmp` directory during the initialization phase, checking for its existence in `/tmp` before downloading it on subsequent invocations.Cevap
  3. C
    Download the model file directly to the `/tmp` directory inside the handler function on every invocation.
  4. D
    Initialize the AWS SDK clients using hardcoded access keys and secret keys inside the handler function.
  5. E
    Configure the Lambda function to run inside a private VPC subnet without an internet gateway or NAT gateway, and access Amazon S3 using the public S3 endpoint.

Cevap

The correct actions are to initialize the Amazon S3 and Amazon DynamoDB SDK client objects outside of the Lambda handler function, and to download the model file to the `/tmp` directory during the initialization phase while checking for its existence in `/tmp` before downloading on subsequent invocations.
The correct options specify initializing SDK clients outside the Lambda handler function and downloading the large static model file to `/tmp` during the initialization phase while checking for its presence first. These techniques take full advantage of AWS Lambda's execution context reuse, avoiding redundant connections and high-volume data transfers on subsequent warm invocations, which dramatically improves performance.

Adım Adım Çözüm

1
Analyze connection reuse practices for AWS Lambda functions.
Initializing SDK clients outside the handler allows the reuse of HTTP connections and clients across invocations, which reduces the time spent on client setup during cold starts and warm invocations.
AWS Lambda reuse of execution contexts is optimized when resource initialization (like client SDK instantiation) occurs during the initialization phase.
2
Evaluate strategies for caching static, large assets in a serverless environment.
Downloading the 250 MB250\text{ MB} model file once to `/tmp` and checking for its presence in subsequent invocations avoids high latency and bandwidth costs associated with fetching the file from Amazon S3 every time.
The `/tmp` directory provides ephemeral local storage that persists as long as the execution context is kept active, which allows for caching static files.
3
Verify VPC network paths for S3 access.
Ensure that the Lambda function is either not placed in a VPC unless necessary, or is placed in a subnet with access to a NAT gateway or S3 VPC Gateway Endpoint to access Amazon S3.
Lambda functions in private VPC subnets cannot reach public AWS endpoints without explicit routing (NAT gateway or VPC endpoint).

Anahtar Kavram

AWS Lambda execution context reuse, client initialization, and ephemeral storage optimization.
Tahmini Süre:2m 0s
Bu soruyu puanla