AWS Serverless and Lambda Architecture 4 — Questions and Answers
Question 1: A Lambda function needs to process messages from an SQS queue but should stop consuming messages when downstream DynamoDB write capacity is exhausted. What is the most operationally efficient approach?
- Set the Lambda reserved concurrency to 0 when throttling occurs
- Use an SQS dead-letter queue and configure Lambda to check DynamoDB capacity before processing
- Configure a Lambda event source mapping with a maximum concurrency limit tied to a CloudWatch alarm that disables the trigger (Correct answer)
- Use Lambda Destinations to route failed invocations back to SQS
Correct answer: Configure a Lambda event source mapping with a maximum concurrency limit tied to a CloudWatch alarm that disables the trigger
Event source mapping maximum concurrency limits how many concurrent Lambda instances process the queue, and a CloudWatch alarm on DynamoDB throttling can disable the ESM trigger to back off.
Question 2: Which Lambda invocation model does Amazon API Gateway use by default when a client makes an HTTP request?
- Asynchronous (Event)
- Synchronous (RequestResponse) (Correct answer)
- Polling
- Streaming
Correct answer: Synchronous (RequestResponse)
API Gateway invokes Lambda synchronously so it can return the function's response directly to the HTTP client.
Question 3: A company wants Lambda functions to access an RDS PostgreSQL database without embedding credentials in environment variables. Which solution follows AWS best practices?
- Store credentials in an S3 bucket and read them at runtime
- Use RDS Proxy with IAM database authentication and grant the Lambda execution role the rds-db:connect permission (Correct answer)
- Pass credentials as encrypted Lambda layers
- Use Systems Manager Parameter Store with SecureString and cache in-memory indefinitely
Correct answer: Use RDS Proxy with IAM database authentication and grant the Lambda execution role the rds-db:connect permission
RDS Proxy with IAM authentication lets Lambda authenticate using its IAM role, eliminating stored passwords and also pooling database connections.
Question 4: What happens to a Lambda function's in-memory state (global variables) between invocations when the same execution environment is reused?
- Global variables are reset to their initial values on every invocation
- Global variables persist across invocations within the same execution environment (Correct answer)
- Global variables are shared across all concurrent execution environments
- Lambda automatically persists global variables to /tmp between invocations
Correct answer: Global variables persist across invocations within the same execution environment
Lambda may reuse execution environments across invocations, meaning global variables and database connections initialized outside the handler persist for the lifetime of the environment.
Question 5: A serverless application uses Step Functions Standard Workflows. Executions occasionally exceed 1 year in duration. What should the architect recommend?
- Switch to Step Functions Express Workflows which support unlimited duration
- Break the workflow into chained executions where each child workflow restarts before the parent's 1-year limit (Correct answer)
- Use an SQS queue with a 14-day retention period between workflow steps
- Enable Step Functions long-polling mode to extend execution duration
Correct answer: Break the workflow into chained executions where each child workflow restarts before the parent's 1-year limit
Standard Workflows have a maximum execution duration of 1 year; for longer processes, chaining executions (where one execution triggers a new one) is the standard pattern.
Question 6: Which AWS service allows you to run containerized workloads in a serverless manner without managing clusters or EC2 instances?
- Amazon ECS with EC2 launch type
- AWS Fargate (Correct answer)
- Amazon EKS with managed node groups
- AWS Batch with spot instances
Correct answer: AWS Fargate
AWS Fargate is a serverless compute engine for containers that removes the need to provision or manage underlying EC2 instances.
Question 7: A Lambda function is configured with a 512 MB memory allocation and consistently completes in 800 ms. After increasing memory to 1024 MB, it completes in 300 ms. What is the cost impact?
- Cost doubles because memory doubled
- Cost decreases because the price per GB-second stays constant but duration dropped by more than 50% (Correct answer)
- Cost is identical because Lambda bills per invocation not per GB-second
- Cost increases slightly because 1024 MB functions are billed at a premium rate
Correct answer: Cost decreases because the price per GB-second stays constant but duration dropped by more than 50%
Lambda billing is GB-seconds (memory × duration): 0.5 GB × 0.8 s = 0.4 GB-s vs 1.0 GB × 0.3 s = 0.3 GB-s, so the higher memory allocation is actually cheaper.
A Lambda function needs to process messages from an SQS queue but should stop consuming messages when downstream DynamoDB write capacity is exhausted.
What is the most operationally efficient approach?