Soru

Zorluk: OrtaServerless Development with AWS Lambda

A developer is developing an AWS Lambda function that processes incoming file uploads from an Amazon S3 bucket. The processed data is then written to an Amazon DynamoDB table. During performance testing, the developer identifies two issues:

1. During peak traffic, the function scales rapidly and consumes all available concurrency in the AWS Region, causing other critical Lambda functions in the account to be throttled.
2. The function experiences elevated latency because it establishes a new connection to DynamoDB on every single invocation.

Which two actions should the developer take to resolve these issues? (Select two.)

  1. Configure reserved concurrency on the S3-triggered Lambda function to limit the maximum number of concurrent instances it can scale to.Cevap
  2. Initialize the DynamoDB client outside of the Lambda handler function to reuse the execution context's connection across multiple invocations.Cevap
  3. C
    Configure provisioned concurrency on the S3-triggered Lambda function to prevent it from exceeding the account's concurrency limits.
  4. D
    Re-initialize the DynamoDB client inside the Lambda handler function on each invocation and call the client's close method at the end of the handler.
  5. E
    Hardcode temporary IAM security credentials directly into the DynamoDB client configuration within the Lambda function to bypass IAM role assumption overhead.

Cevap

Configure reserved concurrency on the S3-triggered Lambda function and initialize the DynamoDB client outside of the Lambda handler function.
The correct options recommend configuring reserved concurrency to prevent the function from scaling past a designated threshold and utilizing execution context reuse by initializing the DynamoDB client outside the handler. Reserved concurrency directly addresses account-level throttling by acting as a hard concurrency cap on the function. Placing the DynamoDB client initialization in the initialization phase (outside the handler function) ensures that the database connection persists in the container and is reused for subsequent warm invocations, avoiding the latency of establishing a new connection on every call.

Adım Adım Çözüm

1
Analyze the first issue regarding unreserved concurrency exhaustion.
Identify that reserving a specific concurrency limit for the S3-triggered function prevents it from scaling indefinitely and consuming the entire account-level pool.
Reserved concurrency acts as a maximum limit for the specific function and guarantees a minimum slice of concurrency, protecting both the function itself and other functions in the account from throttling.
2
Analyze the second issue regarding DynamoDB connection establishment overhead.
Determine that placing the client initialization logic in the global scope (outside the handler) allows the connection to be kept alive and reused across invocations in the same execution context.
AWS Lambda preserves the global scope of the execution context during container reuse, so code executed outside the handler does not run again on warm starts, preventing the creation of new client connections on every request.

Anahtar Kavram

AWS Lambda concurrency limits (Reserved vs Provisioned) and execution context reuse for optimizing downstream database connections.
Bu soruyu puanla