AWS Lambda Flashcards
FaaS stands for
Function as a Service
FaaS is also known as
Serverless computing
Serverless computing is an option for deploying applications on __________
cloud
With serverless compute you install a piece of ___________ on cloud platform
Function
How does AWS executes a function
he cloud platform makes the function available on-demand and manages resource allocation for you.
Design constraints/ design issues with Lambda. When to not use AWS Lambda
- Functions will timeout after 15 minutes.
- The amount of RAM available ranges from 128MB to 3008MB with a 64MB increment between each option.
- The Lambda code should not exceed 250mb in size, and the zipped version should be no larger than 50mb
- For few applications, with huge data size, AWS EC2 may be cheaper
How does AWS charge you for Lambda
AWS charges you for the number of requests your Lambda functions recieve and the time it takes to execute those requests per 100ms.
ETL with Lambda
Extract, Transform, Load (ETL) processes - retrieving data, processing it, and storing the results in a database works well as a function that can be triggered remotely or set up on a schedule.
What are the components of serverless applications?
- Event sources
- Functions
- In some cases services
What are event sources in AWS lambda
An event source is an AWS service or developer-created application that produces events that trigger an AWS Lambda function to run.
Event sources can be _______ and _________ sources
push and pull
What are push event sources
Services publish/push events to Lambda by invoking the cloud function directly.
What are pull event sources ?
For resources that do not publish directly to Lambda, Lambda pulls/polls resources
________________ enables automatic invocation of the Lambda function when events occur.
Event source mapping
What is the function of event source mapping?
Event source mapping identifies the type of events to publish and the Lambda function to invoke when events occur
Push event sources are also referred to as ?
Regular AWS Services.
Push event sources includes
SE, SNS, SES
For push event sources, the event source mapping is maintained on ________
the invoker/S3/SNS
Pull event sources are also referred to as ?
Stream-based event services.
Pull event sources includes
Kinesis, DynamoDB
Event source mapping is maintained on __________side
Lambda’s side.
Can Lambda be used as an event source
Yes. For S3, Lambda,
What happens when a designated event occurs on Lambda’s end ?
When the designated event occurs, the Lambda function runs it own container.
How are resources allocated when a Lambda function launches it’s container?
The resources allocated to the container and the number of containers launched is based on the size of the data and computational requirements of the function, all handled by AWS.
What are the types of Lambda invocation?
- Synchronous invocation
1. Asynchronous invocation
What is synchronous invocation?
When you invoke a function synchronously, Lambda runs the function and waits for a response. When the function completes, Lambda returns the response from the function’s code with additional data, such as the version of the function that was invoked.
What is asynchronous invocation?
When you invoke a function asynchronously, you don’t wait for a response from the function code. You hand off the event to Lambda and Lambda handles the rest.
S3, cloudwatch and SNS invokes functions _______ Sync/Aync)
Asynchronously
What are the parts of Lambda function.
- Handler function
- Event Object
- Context Object
- Callback function (Synchronous invocations)
What is a handler function in Lambda function
When your function is invoked, Lambda runs the handler method and it processes the events
Handler function python syntax
def handler_name(event, context): ... return some_value
What is Event object in Lambda function
An event is a JSON-formatted document that contains data for a Lambda function to process. The Lambda runtime converts the event to an object and passes it to your function code.
What is the default type of Event object ?
Event object is usually of the Python dict type. It can also be list, str, int, float, or the NoneType type.
What is context object in Lambda ?
A context object is passed to your function by Lambda at runtime. This object provides methods and properties that provide information about the invocation, function, and runtime environment.
What is callback function in AWS Lambda function ?
The callback function takes two arguments: an Error and a response. When you call it, Lambda waits for the event loop to be empty and then returns the response or error to the invoke
List Lambda functions in AWS CLI
aws lambda list-functions
What is AWS SAM
AWS Serverless Application Model
Each user can create upto _____ test events per function
10
What is a trigger
A trigger is a resource or configuration that invokes a function
What is an event
Event is a JSON formatted document that contains the data for the Lambda function to process.
How is an event passed to function?
The runtime converts the event to an objects and passes to a function.
What is execution environment ?
Execution environment is an secure and isolated environment for you Lambda function.
What are the responsibilities of execution environment?
Execution environment manages the processes and resources that are required to run a function. Also the execution environment provides any life-cycle support for the function and for any extensions associated with the function.
How do you deploy a function?
You deploy a function using Deployment package.
What are the types of deployment packages?
- .zip file archive
2. Container image
What is the .zip file archive deployment package ?
.zip file archive contains the code and dependencies. Lambda provides the OS and runtime environment to execute the code.
What is the container image deployment package ?
With the container image deployment package, you add the function code, dependencies, OS and Lambda runtime to the image.
The container image of AWS Lambda is compatible with ______________
Open Container Initiative (OCI)
What is runtime?
Runtime provides the language specific environment that runs in a execution environment.
What is the functionality of runtime in AWS Lambda ?
Runtime relays the invocation events, context information, and responses between Lambda and the function.
What is a Lambda Layer ?
A Lambda Layer is a .zip file archive that contains additional code or other content. A Layer can contain libraries, custom runtime, data or configuration files.
How to reduce the size of uploaded deployment archives?
Using Lambda Layers.
What are the advantages of Lambda Layers?
Lambda Layers promote code sharing and separation of responsibilities so that you can iterate faster on writing the business logic.
What is the max number of layers per function
5
Where are the contents of the layers extracted?
The contents of the included layer are extracted to the /opt directory in the execution environment.
What is the default visibility of the Layers
By default the layers you create are private to the AWS account you create.
Can you share the Layers with other AWS accounts?
You can share the layers with other AWS accounts or make it public.
What happens when a shared layer is deleted or when access is revoked?
When a shared layer is deleted or if your access is revoked you can continue to use the layer version but you cannot create a new function or update functions using the deleted version of the layer.
Does functions deployed as containers use Layers ? Why?
No. Container images don’t use layers since all the dependencies are packaged into the container.
What are Lambda extensions?
Lambda extensions enable you to augment your functions. You use extensions to integrate your function with preferred monitoring, observability, security and governance tools.
Types of Lambda extensions.
- Internal extensions.
2. External extensions
Where does internal extension run?
Internal extension within runtime.
What is lifecycle of internal extensions?
Internal extensions shares the same lifecycle as runtime.
Where does external extension run?
External extension runs in the execution environment.
Lifecycle of external extension
External extension is initialized before the function is invoked, runs in parallel with the runtime and continues to run after the function invocation is complete.
What does concurrency denote?
Concurrency is the number of requests your function is serving at a given time.
What is the default quota of the concurrency and what is the max configurable limit ?
1000 and hundreds of thousands
What is qualifier?
Qualifier is used to specify a version or alias.
What is a version
A version is a immutable snapshot of a function’s code and configuration that has numerical qualifier. Example - my-function:1
What is an alias?
Alias is a pointer to a version that you can update to map to a different version or split traffic between two versions
Can alias and version be used together ?
Yes
How Lambda runtime handles multiple events in a row?
When a handler finishes processing the first event, the run time send the handler a second event while the function’s class stays in-memory, so the clients and variables declared outside of the handler method in initialization can be reused.
Once initialized, how many requests can a instance process.
Thousands of requests.
How long does the instances of a Lambda function stay active.
The instances of a function remain active for a few hours before the being recycled.
What communicates the logs to Cloudwatch Logs?
The runtime captures the logging output from the function and sends it to Amazon Cloudwatch logs.
What logs the start and end invocation times
Runtime
What returns the error to invoker if a function throws an error?
Runtime
What tracks or logs the requestID, billed duration and other details
Runtime
When can the log data be lost
- Throttling
2. When instance of the function is stopped.
What is reserved concurrency?
To prevent a function from using too much concurrency, and to preserve a portion of your account’s available concurrency for your function.
What is provisioned concurrency?
For functions that take long time to initialize or that require extremely low latency for all invocations, provisioned concurrency enables you to pre-initialize the instances of your function and keeps them running at all times.
How are retries handled in asynchronous invocation.
If a function returns an error or throttled, Lambda handles the retries.
What are destinations in AWS Lambda
You can add a destination to your functions to send invocation details to another service.
In which invocation can you add destinations?
You can add destinations when your function is invoked asynchronously or by an event source mapping that reads from a stream.
If deployment package is greater than ____, then upload it from S3
50MB
What are environment variables?
Key-value pairs that Lambda sets in execution environment.
What is the purpose of environment variables?
Extend function’s configuration outside of code. For example setting test variables and production variables.
What are tags used for?
Tags are used for organizing Lambda functions for cost reporting and filtering.
What is execution role?
The IAM role that Lambda assumes when running your function.
What is memory?
The amount of memory available at run time.
Min and Max memory values
128 MB - 10,240 MB, 1MB increments.
Timeout
Amount of time Lambda allows a function to run before stopping it.
Default timeout value ? and configurable upto ?
3 seconds and configurable upto 900 secs
What happens when you publish a version?
When you publish a version, the code and most of the configuration settings are locked for that version.
The unpublished version is named _______
$LATEST
The environment variables set in execution environment are made available to the function by ______
Runtime
What creates its own environment variables and what information does it contain?
Runtime creates its own environment variables that are passed to function and they contain information about function and invocation request.
When are environment variables evaluated?
Environment variables are evaluated prior to function invocation.
When you publish a function, the environment variables are ______
locked
You can define the environment variables only in _______ version of the function
Unpublished/$LATEST
Are environment variables encrypted?
Yes
How are environment variables encrypted ?
Lambda encrypts the environment variables at rest with a key it creates in your account for free.
What is key that Lambda creates in your account called?
Amazon Managed Customer Master Key (CMK)
What are the restrictions when you give your own key to encrypt environment variables?
When you provide the key, only users in your account with access to the key can view or manage the environment variables.
What KMS permissions are required for the user or function’s execution role to use the default encryption key?
No AWS KMS permissions are required.
How to allocation more provisioned concurrency than the reserved concurrency?
You can’t allocate more provisioned concurrency than reserved concurrency for a function.
How much concurrency can you reserve?
You can reserve up to the Unreserved account concurrency value that is shown, minus 100 for functions that don’t have reserved concurrency.
When does throttling occur in Lambda functions?
Throttling errors occur when all of the concurrency in a pool is in use.
Advantages of reserved concurrency
- Other functions can’t prevent your function from scaling
2. Your function can’t scale out of control
You can manage provisioned concurrency for ________ and ______ only
Aliases and versions.
How provisioned concurrency works
Provisioned concurrency does not come online immediately after you configure it. Lambda starts allocating provisioned concurrency after a minute or two of preparation. Similar to how functions scale under load, up to 3000 instances of the function can be initialized at once, depending on the Region. After the initial burst, instances are allocated at a steady rate of 500 per minute until the request is fulfilled. When you request provisioned concurrency for multiple functions or versions of a function in the same Region, scaling quotas apply across all requests.
To optimize latency, you can customize the initialization behavior for functions that use provisioned concurrency . You can run initialization code for provisioned concurrency instances without impacting latency, because the initialization code runs at allocation time. However, the initialization code for an on-demand instance directly impacts the latency of the first invocation. For an on-demand instance, you may choose to defer initialization for a specific capability until the function needs that capability.
To determine the type of initialization, check the value of AWS_LAMBDA_INITIALIZATION_TYPE. Lambda sets this environment variable to provisioned-concurrency or on-demand. The value of AWS_LAMBDA_INITIALIZATION_TYPE is immutable and does not change over the lifetime of the execution environment.
For provisioned concurrency instances, your function’s initialization code runs during allocation and every few hours, as running instances of your function are recycled. You can see the initialization time in logs and traces after an instance processes a request. However, initialization is billed even if the instance never processes a request. Provisioned concurrency runs continually and is billed separately from initialization and invocation costs. For details, see AWS Lambda pricing.
Each version of a function can only have one provisioned concurrency configuration. This can be directly on the version itself, or on an alias that points to the version. Two aliases can’t allocate provisioned concurrency for the same version. Also, you can’t allocate provisioned concurrency on an alias that points to the unpublished version ($LATEST).
When you change the version that an alias points to, provisioned concurrency is deallocated from the old version and then allocated to the new version. You can add a routing configuration to an alias that has provisioned concurrency. However, you can’t manage provisioned concurrency settings on the alias while the routing configuration is in place.
What is qualified ARN
With version suffix
Unqualified ARN
Without version suffix
When you invoke a function using an unqualified ARN, Lambda implicitly invokes ______.
$LATEST
An alias can point only to a function _____
version
You can use a __________ to give a service, resource, or account access to your function.
resource-based policy
The scope of permission depends on whether you apply it to _____________
an alias, a version, or the entire function.
What is Alias routing configuration
Use routing configuration on an alias to send a portion of traffic to a second function version.