Lambda Flashcards
How much RAM can you provision for a function?
Up to 10GB
What affect does RAM have on CPU and network?
If you increase the amount of RAM, you will also improve CPU and network.
How can you run a container on Lambda? What should you do for other non-Lambda containers?
Container must implement the Lambda Runtime API
- Other containers should be run on ECS/Fargate
How does Lambda pricing work?
Pay per calls:
- First 1,000,000 requests are free, 20 cents per million after
Pay per duration:
- First 400,000 GB-seconds of compute time free (this means 400,000 seconds if RAM is 1GB, 3,200,000 seconds if 128MB)
- 1 dollar per 600,000 GB seconds after
What are the key sections of the request payload when converting HTTP to JSON for ALB to Lambda?
- Query String Parameters as Key/Value pairs
- Headers as Key/Value pairs
- Body (for POST, PUT…) & isBase64Encoded
What are the key sections of the response when converting HTTP to JSON for ALB to Lambda?
- Headers as Key/Value pairs
- Body & isBase64Encoded
How can you use ALB Multi-Header Values with Lambda?
Enable the ALB setting for Multi-Header values
- This will allow you to pass in multiple HTTP headers or query string parameters with the same key, which will be shown as an array within the AWS Lambda event
How does Lambda handle Asynchronous Invocations? What considerations should be made because of this?
Events are placed in an Event Queue
- Lambda attempts to retry on errors up to 3 times
- Make sure processing is idempotent
- Use a DLQ for failed processing
What services invoke Lambda Asynchronously?
S3, SNS, CloudWatchEvents/EventBridge
What sources does Lambda have to poll data from? Is this sync or async?
Kinesis Data Stream, SQS & FIFO queue, DynamoDB Streams
- Sync
How does an event source mapping work for Streams (Kinesis and DDB)?
Creates an iterator for each shard and processes items in order
- processed items aren’t removed from the stream (other consumers can read them)
How could you set up event source mapping for streams at low and high traffic?
Low: use batch window to accumulate records before processing
High: process multiple batches in parallel - up to 10 batches per shard, with in-order processing still guaranteed for each partition key
How does an error affect batch processing for event source mapping of streams?
By default, an error causes the entire batch to be reprocessed until the function succeeds or the items in the batch expire
- to maintain in-order processing, processing for the affected shard is paused until the error is resolved
How can you configure event source mapping re. errors for streams?
- Discard old events
- Restrict number of retries
- Split batch on error (to work around Lambda timeout issues)
Discarded events can go to a Destinatation
How can you set up event source mapping for SQS?
- ESM will pool SQS (Long polling)
- Specify batch size
- Recommended to set queue visibility timeout to 6x the timeout of the lambda function
- To uses a DLQ, set it up in SQS, NOT in Lambda (Lambda DLQ is only for async invocations)
How does Lambda scale with FIFO SQS Queues?
Scales up to the number of active message groups
How does an error for Lambda and Queues affect batches?
Errors cause batches to be returned to the queue as individual items that might be processed in a different grouping than the original batch
How many stream batches can be processed per shard?
If you use parallelization, up to 10 batches per shard.
What is the difference between the Lambda Event and Context Objects?
Event Object:
- JSON formatted document contains data for the function to process
Context Object:
- Metadata around the invocations, function and runtime environment, provided by Lambda at runtime
What is the purpose of Lambda Destinations? Why are they recommended over DLQ?
Configure Lambda to send result (can decide for both success or failure) of function to a Destination (useful for asynchronous invocations)
- SQS, SNS, Lambda and EventBridge
DLQ is only for SQS, but Destinations have a range of options
Where can you route failed event batches to from an Event Source mapping?
SQS or SNS
- Can send to DLQ directly from SQS
Why might a failed S3 event processing in a Lambda function not appear in the destination straight away?
S3 events are sent asynchronously - Lambda retries processing 3 times for asynchronous events.
What are the differences in IAM roles regarding Lambda?
- Resource-based policies allow the Lambda function to be invoked by other services
- Policies attached to the Lambda execution IAM role allow the Lambda function to invoke other services
What three environment variables allow Lambda to communicate with X-Ray?
_X_AMZN_TRACE_ID - contains the tracing header
AWS_XRAY_CONTEXT_MISSING: by default, LOG_ERROR
AWS_XRAY_DAEMON_ADDRESS: the X-Ray Daemon IP_ADDRESS:PORT