0
0
AWScloud~30 mins

Lambda layers for shared code in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Lambda layers for shared code
📖 Scenario: You are building two AWS Lambda functions that both need to use the same helper code. Instead of copying the helper code into each function, you will use a Lambda layer to share the code.
🎯 Goal: Create a Lambda layer with shared helper code, then configure two Lambda functions to use this layer.
📋 What You'll Learn
Create a Lambda layer named shared_helpers with a Python helper function
Create two Lambda functions named function_one and function_two
Configure both Lambda functions to use the shared_helpers layer
💡 Why This Matters
🌍 Real World
Sharing common code across multiple Lambda functions reduces duplication and simplifies maintenance.
💼 Career
Understanding Lambda layers is important for AWS developers and cloud engineers to build efficient serverless applications.
Progress0 / 4 steps
1
Create the shared helper code for the Lambda layer
Create a folder named python and inside it create a file named helper.py with a function def greet(name): that returns the string f"Hello, {name}!".
AWS
Need a hint?

Remember, the Lambda layer code must be inside a folder named python at the root of the zip file.

2
Create the Lambda layer configuration
Create a variable named layer_name and set it to the string 'shared_helpers' to name your Lambda layer.
AWS
Need a hint?

Use a simple assignment to create the layer_name variable.

3
Create two Lambda functions that use the shared layer
Create two variables named function_one and function_two. Assign each a dictionary with keys 'FunctionName' set to 'function_one' and 'function_two' respectively, and 'Layers' set to a list containing layer_name.
AWS
Need a hint?

Each function configuration must include the Layers key with a list containing the layer_name.

4
Add the layer ARN to the Lambda functions
Create a variable named layer_arn and set it to the string 'arn:aws:lambda:us-east-1:123456789012:layer:shared_helpers:1'. Then update the 'Layers' list in both function_one and function_two to contain only layer_arn.
AWS
Need a hint?

The layer ARN is a string that uniquely identifies the Lambda layer version.