AWS Lambda Starter guide_2024_12_01
AWS Lambda Starter guide_2024_12_01
The Power
of AWS
Lambda
The Term
“Serverless”
Lambda is a serverless compute service
that lets you run code without provisioning
or managing servers.
Key points:
Serverless Paradigm: Emphasizes the shift
from traditional server management to
deploying code in the form of functions.
Click “Save”
Creating a
Lambda Function
Run the Test:
Click on Test
Review Results:
Check the execution results.
Lambda Execution
Role
Execution Role grants the Lambda function permissions to AWS
services / resources
Access Control:
An IAM principal can access a Lambda function if:
The IAM policy attached to the principal authorizes it (e.g.,
user access).
The resource-based policy authorizes it (e.g., service
access).
Service Invocation:
When an AWS service like Amazon S3 calls your Lambda
function, the resource-based policy grants it the necessary
access.
Example Policy:
Lambda Environment
Variables
Purpose:
Environment variables allow you to configure various aspects of
your Lambda function's behavior without modifying its code.
Security Considerations:
AWS provides integration with Key Management Service (KMS) to
encrypt environment variables, ensuring that sensitive data
remains protected.
Lambda Environment
Variables
Navigate to Configuration tab:
In Node.js:
In Python:
AWS Lambda
Integrations
Main Ones:
Navigate to S3
Console
Destination: Choose
"Lambda function” and
select the function you want
to trigger.
Navigate to DynamoDB
Console.
Select the table, Click on the "Exports and streams” tab in the
table details view.
Go to the "Configuration”
tab of your Lambda
function.
In the trigger
configuration pane,
select "DynamoDB”
as the trigger type.
Creating Event Source
Mapping
Configure the Trigger:
Select the DynamoDB table that you have enabled streams for.
Starting Position:
TRIM_HORIZON to start from the oldest available record.
LATEST to start from the newest record.
Example Structure:
Event Object
Context Object
Lambda, Event and
Context Objects
Handling Events in Lambda Function
Example of a Lambda function written in Python that processes
DynamoDB stream events:
Lambda Limits to Know
per region
Execution:
Memory allocation: 128 MB – 10GB (1 MB increments)
Deployment:
Lambda function deployment size (compressed .zip): 50 MB
Key Concepts
Layer Creation:
Layers are created separately from Lambda functions.
Each layer can contain libraries, a custom runtime, or other
dependencies.
You can create a layer from the AWS Management Console, AWS CLI, or
AWS SDKs.
Layer Versions:
Layers are versioned. Each update to a layer creates a new version.
You can specify which version of the layer to use with your Lambda
function.
Layer Usage:
You can use up to five layers in a single Lambda function.
Layers can be shared across accounts and with the public.
Layer Content:
Layers can include libraries, binaries, custom runtimes, and other files.
The content must be in a ZIP file when uploading.
Creating Lambda
Layers
Go to the Lambda
console.
Select "Layers”
from the left-hand
navigation.
Click "Create
layer”.
Creating Lambda
Layers
Provide a Name to
the Layer
Click "Create”.
Click "Add”
Lambda Layers
Best Practices
Use Layers for Dependencies:
Include common libraries and dependencies in layers to
keep the function deployment package small.
Version Control:
Maintain version control for layers. Test new versions before
updating functions to ensure compatibility.
Security:
Secure sensitive data within layers using encryption and IAM
policies.
Use AWS KMS to encrypt sensitive information stored in
layers.
Next Week I‘m covering the Advanced
Lambda Topics on my Newsletter.
FOLLOW FOR
MORE GUIDES!