AWS - Lambda Quizlet
AWS - Lambda Quizlet
AWS - Lambda Quizlet
What is Lambda
AWS Lambda is a serverless compute service that runs your code in response to events and
automatically manages the underlying compute resources for you.
Lambda Description
AWS Lambda lets you run code without provisioning or managing servers. You pay only for
the compute time you consume - there is no charge when your code is not running.
Lamda Features
-- Event Driven
-- Serverless
-- Run as a compute service in response to HTTP requests using API Gateway or API calls
-- scale out automatically
Lambda Supported Event Sources
-- S3
-- DynamoDB
-- Kinesis Data Streams
-- Kinesis Data firehose
-- SNS
-- SES
-- Cognito
-- CloudFormation
-- CloudWatch Logs
-- CloudWatch Events
-- CloudFront
-- API Gateway
-- Codecommit
-- Alexa
-- Scheduled event
-- AWS IOT
Lambda benefits
-- Serverless, NO SERVERS TO MANAGE
-- Continuous scaling
--SUBSECOND METERING: you are charged for every 100ms your code executes and the
number of times your code is triggered
What languages does AWS Lambda support
Node.js (JavaScript), Python, Java (Java 8 compatible), and C# (.NET Core) and Go
Lambda function diskspace
Lambda function receives 500MB of non-persistent disk space in its own /tmp directory.
How does Lambda function scale
Lambda scales them automatically
Lambda can start as - many copies of your function as needed without lengthy deployment
and configuration delays
Debug Lambda
AWS X-ray is used for debug Lambda function
role to be used to use Lambda function
Simple Microservice Permission
Terms in this set (17)
For ordered event sources that AWS Lambda polls on your behalf, such as Amazon
DynamoDB Streams and Amazon Kinesis streams, Lambda will continue attempting
execution in the event of a developer code error until the data expires. You can
monitor progress through the Amazon Kinesis and Amazon DynamoDB consoles
and through the Amazon CloudWatch metrics that AWS Lambda generates for your
function. You can also set Amazon CloudWatch alarms based on error or execution
throttling rates.
What is a serverless application?
A typical serverless application consists of one or more functions triggered by events
such as object uploads to Amazon S3, Amazon SNS notifications, or API actions.
These functions can stand alone or leverage other resources such as DynamoDB
tables or Amazon S3 buckets. The most basic serverless application is simply a
function.
How do I deploy and manage a serverless application?
You can deploy and manage your serverless applications using the AWS Serverless
Application Model (AWS SAM). AWS SAM is a specification that prescribes the rules
for expressing serverless applications on AWS. This specification aligns with the
syntax used by AWS CloudFormation today and is supported natively within AWS
CloudFormation as a set of resource types (referred to as "serverless resources").
These resources make it easier for AWS customers to use CloudFormation to
configure and deploy serverless applications, using existing CloudFormation APIs.
How can I discover existing serverless applications developed by the AWS
community?
You can choose from a collection of serverless applications published by developers,
companies, and partners in the AWS community with the AWS Serverless
Application Repository. After finding an application, you can configure and deploy it
straight from the Lambda console.
How do I automate deployment for a serverless application?
You can automate your serverless application's release process using AWS
CodePipeline and AWS CodeDeploy. CodePipeline is a continuous delivery service
that enables you to model, visualize and automate the steps required to release your
serverless application. CodeDeploy provides a deployment automation engine for
your Lambda-based applications. CodeDeploy lets you orchestrate deployments
according to established best-practice methodologies such as canary and linear
deployments, and helps you establish the necessary guardrails to verify that newly-
deployed code is safe, stable, and ready to be fully released to production.
How do I get started on building a serverless application?
To get started, visit the AWS Lambda console and download one of our blueprints.
The file you download will contain an AWS SAM file (which defines the AWS
resources in your application), and a .ZIP file (which includes your function's code).
You can then use AWS CloudFormation commands to package and deploy the
serverless application that you just downloaded.
How do I coordinate calls between multiple AWS Lambda functions?
You can use AWS Step Functions to coordinate a series of AWS Lambda functions
in a specific order. You can invoke multiple Lambda functions sequentially, passing
the output of one to the other, and/or in parallel, and Step Functions will maintain
state during executions for you.
How do I troubleshoot a serverless application?
You can enable your Lambda function for tracing with AWS X-Ray by adding X-Ray
permissions to your Lambda function's execution role and changing your function's
"tracing mode" to "active. " When X-Ray is enabled for your Lambda function, AWS
Lambda will emit tracing information to X-Ray regarding the Lambda service
overhead incurred when invoking your function. This will provide you with insights
such as Lambda service overhead, function init time, and function execution time. In
addition, you can include the X-Ray SDK in your Lambda deployment package to
create your own trace segments, annotate your traces, or view trace segments for
downstream calls made from your Lambda function. X-Ray SDKs are currently
available for Node.js and Java.
What is Lambda@Edge?
Lambda@Edge allows you to run code across AWS locations globally without
provisioning or managing servers, responding to end users at the lowest network
latency. You just upload your Node.js code to AWS Lambda and configure your
function to be triggered in response to Amazon CloudFront requests (i.e., when a
viewer request lands, when a request is forwarded to or received back from the
origin, and right before responding back to the end user). The code is then ready to
execute across AWS locations globally when a request for content is received, and
scales with the volume of CloudFront requests globally.
How do I use Lambda@Edge?
To use Lambda@Edge, you just upload your code to AWS Lambda and associate a
function version to be triggered in response to Amazon CloudFront requests. Your
code must satisfy the Lambda@Edge service limits. Lambda@Edge only supports
Node.js for global invocation by CloudFront events at this time. L
When should I use Lambda@Edge?
Lambda@Edge is optimized for latency sensitive use cases where your end viewers
are distributed globally. All the information you need to make a decision should be
available at the CloudFront edge, within the function and the request. This means
that use cases where you are looking to make decisions on how to serve content
based on user characteristics (e.g., location, client device, etc) can now be executed
and served close to your users without having to be routed back to a centralized
server.
Can I deploy my existing Lambda functions for global invocation?
You can associate existing Lambda functions with CloudFront events for global
invocation if the function satisfies the Lambda@Edge service requirements and
limits.
What Amazon CloudFront events can be used to trigger my functions?
Your functions will automatically trigger in response to the following Amazon
CloudFront events:
Viewer Request - This event occurs when an end user or a device on the Internet
makes an HTTP(S) request to CloudFront, and the request arrives at the edge
location closest to that user.
Viewer Response - This event occurs when the CloudFront server at the edge is
ready to respond to the end user or the device that made the request.
Origin Request - This event occurs when the CloudFront edge server does not
already have the requested object in its cache, and the viewer request is ready to be
sent to your backend origin webserver (e.g. Amazon EC2, or Application Load
Balancer, or Amazon S3).
Origin Response - This event occurs when the CloudFront server at the edge
receives a response from your backend origin webserver.
How is AWS Lambda@Edge different from using AWS Lambda behind Amazon API
Gateway?
The difference is that API Gateway and Lambda are regional services. Using
Lambda@Edge and Amazon CloudFront allows you to execute logic across multiple
AWS locations based on where your end viewers are located.
Is there a limit to the number of AWS Lambda functions I can execute at once?
No. AWS Lambda is designed to run many instances of your functions in parallel.
However, AWS Lambda has a default safety throttle for number of concurrent
executions per account per region
What happens if my account exceeds the default throttle limit on concurrent
executions?
On exceeding the throttle limit, AWS Lambda functions being invoked synchronously
will return a throttling error (429 error code). Lambda functions being invoked
asynchronously can absorb reasonable bursts of traffic for approximately 15-30
minutes, after which incoming events will be rejected as throttled. In case the
Lambda function is being invoked in response to Amazon S3 events, events rejected
by AWS Lambda may be retained and retried by S3 for 24 hours. Events from
Amazon Kinesis streams and Amazon DynamoDB streams are retried until the
Lambda function succeeds or the data expires. Amazon Kinesis and Amazon
DynamoDB Streams retain data for 24 hours.
What happens if my Lambda function fails during processing an event?
On failure, Lambda functions being invoked synchronously will respond with an
exception. Lambda functions being invoked asynchronously are retried at least 3
times. Events from Amazon Kinesis streams and Amazon DynamoDB streams are
retried until the Lambda function succeeds or the data expires. Kinesis and
DynamoDB Streams retain data for a minimum of 24 hours.
What happens if my Lambda function invocations exhaust the available policy?
On exceeding the retry policy for asynchronous invocations, you can configure a
"dead letter queue" (DLQ) into which the event will be placed; in the absence of a
configured DLQ the event may be rejected. On exceeding the retry policy for stream
based invocations, the data would have already expired and therefore rejected.
What resources can I configure as a dead letter queue for a Lambda function?
You can configure an Amazon SQS queue or an Amazon SNS topic as your dead
letter queue.
How do I allow my AWS Lambda function access to other AWS resources?
You grant permissions to your Lambda function to access other resources using an
IAM role. AWS Lambda assumes the role while executing your Lambda function, so
you always retain full, secure control of exactly which AWS resources it can use.
How do I control which Amazon S3 buckets can call which AWS Lambda functions?
When you configure an Amazon S3 bucket to send messages to an AWS Lambda
function a resource policy rule will a be created that grants acces
How do I control which Amazon DynamoDB table or Amazon Kinesis stream an
AWS Lambda function can poll?
Access controls are managed through the Lambda function's role. The role you
assign to your Lambda function also determines which resource(s) AWS Lambda
can poll on its behalf.
How do I control which Amazon SQS queue an AWS Lambda function can poll?
Access controls can be managed by the Lambda function's role or a resource policy
setting on the queue itself. If both policies are present, the more restrictive of the two
permissions will be applied.
Can I access resources behind Amazon VPC with my AWS Lambda function?
Yes. You can access resources behind Amazon VPC.
How do I enable and disable the VPC support for my Lambda function?
To enable VPC support, you need to specify one or more subnets in a single VPC
and a security group as part of your function configuration. To disable VPC support,
you need to update the function configuration and specify an empty list for the
subnet and security group. You can change these settings using the AWS APIs, CLI,
or AWS Lambda
Can a single Lambda function have access to multiple VPCs?
No. Lambda functions provide access only to a single VPC. If multiple subnets are
specified, they must all be in the same VPC. You can connect to other VPCs by
peering your VPCs.
Can Lambda functions in a VPC also be able to access the internet and AWS
Service endpoints?
Lambda functions configured to access resources in a particular VPC will not have
access to the internet as a default configuration. If you need access to external
endpoints, you will need to create a NAT in your VPC to forward this traffic and
configure your security group to allow this outbound traffic.
stateless style
It is best practice to write a AWS Lambda function in a stateless style. It should not
have any affinity with the underlying compute infrastructure.
persistent state
Persistent state should be stored in another cloud service, such as Amazon S3 or
DynamoDB.
lambda handler
It is a recommended to separate core logic from the Lambda handler as the handler
is generally used as an entry point to the function
deploy over a VPC
When a Lambda function is deployed over a VPC, it is a best practice to avoid DNS
resolution for a public hostname, as it may take several seconds to resolve and it
adds several billable seconds.
subnet
It is recommended to specify at least one subnet in each AZ with the Lambda
function configuration.
sufficient subnet IPs
It is recommended to make sure sufficient subnet IPs are free to allow Lambda
functions to scale. If there aren't any free subnet IPs, Lambda functions will not scale
and Lambda function failure will increase.
Static initialization
Rather than re-initializating variables or objects on every invocation, use static
initialization or constructor, global, or static variables and singletons. It helps to
improve the performance of the Lambda function.
reuse connection
Where possible, keep alive and reuse connections such as database or HTTP that
were established in an earlier invocation.
environmental variables
To cope with frequent changes in the operational parameters, pass them using
environment variables to avoid frequent changes in a Lambda
all the dependencies
It is a best practice to pack all the dependencies in a deployment of a Lambda
function. Where possible, control the dependencies in the Lambda function to
minimize the overall size and execution time.
java programming
If you are using a Java programming language, put dependencies in a separate /lib
directory rather than putting all functions, source code in a single jar with a large
number of .class files.
simple framework
It is highly recommended to use a simple framework and minimize the complexity of
the dependencies to quickly load the container startup.
monitor lambda functions
It is a best practice to use Lambda metrics and CloudWatch alarms to monitor
Lambda functions health rather than creating and maintaining custom metrics from
Lambda function code.
memory
The amount of memory that can be allocated to a Lambda function ranges between
128 and 1536 MB. The minimum memory that can be allotted to a Lambda function
is 128 MB. Based on the requirement, you can allot more memory in increments of
64 MB
parameters
Maximum execution time (timeout): The maximum it can be 5 minutes
IAM role (execution role): Lambda can assume an IAM role at the time of execution
Handler name: It refers to the method name to be used by AWS Lambda to start the
execution.
code for a Lambda function
Handler
The context object
Logging
Exceptions
deploying
Once the source code is converted into a deployment package, it can either be
directly uploaded to Lambda from the local machine or first to an Amazon S3 bucket.
The S3 bucket should be in the same region where the Lambda function is being
created. Specify the same S3 link URL while creating a Lambda function.
alia
An alias can only point to the function version. It cannot point to another alias.
stream base aws service
Out of all the supported AWS services, Amazon Kinesis Streams and Amazon
DynamoDB streams are the only stream-based AWS services. The rest of the
services are regular AWS services.
e.g.
callback(null, success)
Can you fee the callback function a variable in place of success message?
Yes, e.g.
callback(null, A)
AWS lambda advanced does not specify CPU etc ? So, what do you do you do if your
function will be resource intensive?
increase the memory size. You will get more (equivalent) CPU power
What is the minimum amount of memory you can assign to a lambda function?
128MB
What is the default timeout for a lambda function?
3 seconds
What happens if your function runs longer than the timeout limit specified?
AWS will just kill it and return an error message
why would a lambda function need a vpc?
If the function needs to access resources that live within a VPC e.g. elasticache, RDS,
redshift)
In the lambda configuration there is a setting for hander: It is set to index.handler. What does
that mean?
When you wrote you function, you called your called your handler function (javascript)
literally "handler". So, it refers to that. I guess , here "index" is like a predetermined key word
If you just ran a "test" of a lambda function, how do you know how much time/memory it
took?
Right below "Execution Result: Succeeded", there is a TOGGLE for "Details.
e.g. One lambda function can process both GET and POST
3 ways you can create a Lambda function:
Console
CLI
SDK
In a Python function how do you use "json" library?
import json
Lambda function executes in a _______ environment without any display
Headless
In Node.js , how do you end your function?
callback
In Python, how do you end your function?
return
If your function is rarely used, the next execution maybe slower , why?
AWS would have released your function execution environment
How can you call your function using AWS Lambda's API?
Use AWS CLI
Can you choose API Gateway as a Trigger?
Yes
You can also use it in conjunction with API gateway to respond to HTTP requests
What languages are supported by lambda?
Nojde.js, Java, Python, C#, Go
How is lambda priced
By number of requests (first 1 million are free, then 20 cents per million requests
thereafter) and by duration (calculated from the time your code begins executing).
how does Lambda scale
out (not up). This means you can have millions of functions running in parallel, but if
you run out of memory you need to upgrade the amount of memory
What does it mean that lambda functions are independent
1 event = 1 function
What can you use to debug lambda?
X-Ray
Can you use Lambda for global functions, like to back up an S3 bucket?
Yes
What services can trigger lambda functions?
S3, DynamoDB, Kinesis Data Streams, SNS, SES, SQS, Cognito, Cloudformation,
Cloudwatch, Alex, API Gateway, Cloudfront
What do restful apis look like?
key-value pairs like json
What does the SOAP API use?
XML and it's old as shit. Looks like html.
What is API Gateway?
Allows you to create an API that acts as a front door/waiter for applications to access
data, business logic, or functionality from back end services like EC2 or code running
on lambda
How do you configure API Gateway
1. Define an API (container)
2. Define resources and nested resources (URL paths)
3. Select a supported HTTP verb for each resource
4. set security
5. choose target (EC2, Lambda, DynamoDB, etc)
6. Set request/response transformations
7. Deploy to a stage (test, prod, etc)
What is API caching?
Allows you to cache common endpoint responses to increase performance. That
way, you reduce actual calls to your API and just send the response.
How long do API responses stay cached when you enable API caching?
A TTL in seconds
What should you do if you see an error that says "Origin policy cannot be read at the
remote resource"
Enable CORS on API Gateway
Can you publish more than one version of a lambda function?
You know you can! And they all have a unique ARN
What are the types of ARNS you can refer to your lambda function with?
Qualified ARN: has a version suffix
Unqualified ARN: no version suffix
Can you edit lambda versions after you publish them?
No, you can only edit the latest version, called $latest
What are Lambda Aliases?
A name that points to a particular version of your function -- Prod can point to version
one, Test to version 2, etc.
How can you split traffic?
Using aliases into different versions
Can you split traffic with $latest?
Nope. Need to create an alias to latest instead.
What are step functions?
Allow you to visualize and test serverless applications that provide a graphic console
to arrange and visualize components of apps. It logs state of each step so you can
diagnose and debug quickly.
What is X-Ray?
A service that collects data about requests that your application serves and provides
tools you can use to view and gain insights about that data.
What kind of data can you see with X-Ray on traced requests to your app?
Info about rqwuest, response, calls your app makes to downstream AWS resources,
HTTP web apis, etc
How does X-ray work?
1. X-Ray SDK is installed in your app
2. Sends JSON-style docs to X-Ray Daemon
3. Which sends it to the X-Ray API
4. Where you can see a visualization on what's happening with your data
What does the X-Ray SDK provide?
1. Interceptors to add to your code to trace incoming HTTP requests
2. Client handlers to create sdk clients your app uses to call other AWS services
3. A http client to create calls to other internal and external http web services
What does X-Ray integrate with?
Elastic Load Balancing, Lambda, API Gateway, EC2, elastic beanstalk
How can you import API Gateways?
Using the API gateway import that supports Swagger v2.0 definition files
What can you do with Import API?
1. create a new API by submitting a post request
2. Update an existing API by using a put request that contains a swagger definition in
the payload.
What is API Gateway's default limit for request rates/second?
10,000
What is the max concurrent request rate across all APIs?
5000
What do you get if you violate the max concurrent request rate or the default limit for
request rates/second?
A 429 (too many requests) error
What happens if a caller sends 10,000 rquests in the first millisecond?
API gateway serves 5,000 of those request and then throttles the rest within a one
second period.