AWS lambda and layers
How to add a layer made with numpy and pandas and allow your lambda to call it.
Create a package
#!/bin/bash
# 🔧 Configurable variables
LAYER_NAME="pandas-layer"
PYTHON_VERSION="3.10"
PACKAGE_DIR="python"
ZIP_NAME="${LAYER_NAME}.zip"
mkdir -p $PACKAGE_DIR
python$PYTHON_VERSION -m pip install pandas numpy -t $PACKAGE_DIR
echo " Creating zip file..."
zip -r $ZIP_NAME $PACKAGE_DIR
echo " Layer package created: $ZIP_NAME"
Add this package to your lambda layer


Create a lambda using Python 3.10 here then setup the layer

Lambda code
here an example using pandas
import json
import pandas as pd
def lambda_handler(event, context):
data = {
"Nom": ["Alice", "Bob", "Charlie"],
"Âge": [25, 30, 35]
}
df = pd.DataFrame(data)
return {
"statusCode": 200,
"body": df.to_json(orient="records", force_ascii=False)
}