AWS 19 Flashcards
Docker can run on lambda, true or false?
False
When is Lambda synchronously invoked?
ELB; API Gateway; CloudFront; Amazon S3 Batch; Amazon Cognito; AWS Step Functions
How do we register Lambda with an ALB?
Make sure Lambda is registered in a target group
What are multi-value headers in an ALB and Lambda?
When you have HTTP headers or query string paramaters that are sent with multiple values, they are shown as arrays within the AWS Lambda event and response objects;
*It is a setting on the ALB
What allows the ALB to invoke the lambda?
A resource based policy. Remember, we set a resource based policy when other services want to communicate with lambda
What is Lambda@Edge?
We can deploy Lambda functions alongside your CloudFront CDN to build more responsive applications;
You can use Lambda to change CloudFront request and responses
What triggers Lambda asynchronously?
S3, SNS, CloudWatch Events/EventBridge
How does Asynchronous Lambda work? What is it good for?
The events are placed in an Event Queue;
It is good for speeding up processes you don’t need to wait for
How do we make sure an event is sent from S3 to Lambda for every successful write?
Make sure versioning is enabled. It is possible that two writes can be made to the same bucket and only one notification is sent if non-versioning is enabled.
What three services can Lambda event source map?
Kinesis streams, SQS & SQS FIFO queu, DynamoDB streams
When Lambda does event source mapping, is this a syncronous operation or async?
Synchronous because Lambda needs to poll from the source and then triggers a Lambda function
For Lambda and Streams, what happens if a function returns an error?
The entire batch is reprocessed until success or batch is expired
Lambda ESM will poll SQS using what method?
Long Polling
To set up a DLQ for Lambdas ESM with SQS, what do we do?
We must set it up on the SQS queue, not Lambda (DLQ for Lambda is only for async invocations)
For Lambda and FIFO queue, scaling lambdas up to number of active message groups is permitted, true or false?
True
How can we speed up processing with Lambda and Streams?
We can process multiple batches in parallel;
Up to 10 batches per shard;
For streams and parallelization, in-order processing is not guaranteed for each partition key, true or false?
False. It is guaranteed
For processing async invocations in Lambda, we should make sure the logic is?
Idempotent, in case of retries. The same invocation will produce the same result
Before an async invocation hits the lambda, where does it go?
It goes through an internal event queue in Lambda
What is the Event Source Mapping in Lambda used for?
Polling and receiving a batch from a stream source
When an error occurs with Lambdas and queues, what happens?
Remember that this would be for Event Source Mapping;
Batches are returned to the queue as individual items and might be processed in different grouping than the original batch
How can we handle errors in Lambda event source mapping with streams?
Restrict the number of retries;
Split the batch on error (to work around Lambda timeout issues);
Set a destination for failed events;
What is the idea of destinations in Lambda?
To send the result of an async invocation or an event mapper to a specified location
What are our Destinations for Lambda async invocations?
SQS, SNS, Lambda, EventBridge
Lambda Destinations work for both success and failed processes, true or false?
False. Async operations can define destinations for both successful and failed events;
The event source mapper can only be for discarded events
What are the destinations for Async operations for lambda? What about ESM?
SQS, SNS, Lambda, EventBridge Bus;
SQS, SNS
We should create one Lambda Execution Role to cover all functions, true or false?
False. Create a Lambda execution role for each function
When do we use Lambda Execution Role vs Resource Based Policies?
We use the Execution Role to invoke other services and we use resource based policy to grant other services access to our Lambda
Lambda cannot write to CloudWatch for logging; what could be the issue?
We don’t have the proper execution role for the Lambda
How do we enable Lambda tracing with X-Ray?
Enable in Lambda configuration (Active Tracing);
Use AWS X-Ray SDK in Code;
Ensure Lambda Function has a correct IAM Execution Role;
Environment Variables to communicate with X-Ray
What are the three env variables for Lambda to run with X-Ray?
_X_AMZN_TRACE_ID
AWS_XRAY_CONTEXT_MISSING
AWS_XRAY_DAEMON_ADDRESS
By default, your Lambda is launched in your own VPC, true or false?
False. It is launched in an AWS owned VPC
How do we put a Lambda in our VPC?
Define the VPC ID, the Subnets and the Security Groups;
We also need the proper VPC Access Execution Role
**A lambda function inside your VPC has internet access, true or false?
False. By default it does not have Internet Access. Deploying it to a public subnet does not give it internet access.
How do we give AWS Lambda internet access?
We must route outbound traffic to a NAT gateway in a public subnet
Multiple Lambda functions connected to the same subnets share network interfaces, true or false?
True
How do we get more vCPU credits with Lambda?
Increase the RAM
What is the default timeout for lambda? What is the maximum?
3 seconds, 15 minutes
What is the Lambda execution environment?
The execution environment manages the resources needed to run your function
We need to put DB connections in our handler for our Lambdas, true or false?
False. We put it in the execution context or in the code above the handler
We want a limit for concurrent Lambda executions. What do we do?
Set a reserved concurrency;
For each invocation over the concurrency limit will trigger a “Throttle”;
What is the throttle behavior for Lambda async vs sync?
Sync returns a ThrottleError;
Async will return the item to the event queue and then retry;
Async wont return an error because it automatically returns a 202
What is provisioned concurrency?
We allocate concurrency before the function is invoked. This helps improve cold starts. Application Auto Scaling can manage provisioned concurrency based of metrics.
What is reserved concurrency?
It allocates a specific amount of concurrency to a function so that no other function can use that concurrency. This however limits the maximum amount of concurrency for that function.
If our lambda depends on external libraries, what do we do?
We install the packages alongside the code and zip it all together
We updated Lambda code stored in S3, but CloudFormation doesn’t pick up the change? Why not?
We need to update the S3Bucket, S3Key or S3ObjectVersion in the Template or else CloudFormation won’t update the function
What are Lambda Layers used for?
Custom Runtimes (Rust, C++); Externalize Dependencies to re-use them;
What are lambda aliases?
Aliases are “pointers” to Lambda function versions, we can send users/actions through aliases to versions, even weighted (PROD alias will send 90% to V1 and 10% to V2)
Lambda aliases may point to lambda aliases, true or false?
False
How can we use Lambda and CodeDeploy together?
CodeDeploy can help us automate traffic shift for Lambda aliases. We can have weighted traffic to Lambda versions.
What is the memory allocation for Lambda?
128 MB - 3008 MB
What is the maximum amount of environment variables for Lambda?
4 KB
What is the max deployment size for Lambda for compressed and uncompressed?
50 MB;
250 MB;
You have a Lambda function that will process data for 25 minutes before successfully completing it. The code is working fine on your machine, but in AWS Lambda it just fails with a “timeout” issue after 3 seconds. What should you do?
Run your code somewhere else - Lambda only supports 15 minute timeout
Your lambda function is invoked asynchronously and some events fail from being processed after 3 retries. You’d like to collect and analyze these events later on. What should do you?
Add a DLQ to send messages to SQS
You are looking to invoke an AWS Lambda function every hour (similar to a cron job) in a serverless way. Which event source should you use for your AWS Lambda function?
CloudWatch Events
What is the best way to send the result of an asynchronous Lambda function to SQS?
Use a destination
What two ways can we configure error handling for async invocations for Lambda?
Maximum age of an event;
Retry attempts;
When either of these are exceeded, lambda will discard the events. We can configure a failed-event destination;