-
Note that
aws-xray-sdk
is not a natively supported package in lambda. -
Let's create a layer in order to make
aws-xray-sdk
importable into our lambda function in python. -
Make sure we have conda installed, and put
source ~/anaconda3/etc/profile.d/conda.sh
in our
~/.bashrc
, this is to make sureconda
is identifiable as a executable command.
-
Open an empty folder and
cd
into it -
pip install -t $(pwd) aws-xray-sdk
-
Create a new folder named
python
, drag all package related files into it, and zip thatpython
folder -
Go to Layers and click
Create Layer
-
Upload the
zip
file and we are ready to go. -
Test the import statement which originally throwed error without our additional layer:
import json from aws_xray_sdk.core import xray_recorder def lambda_handler(event, context): # TODO implement return { 'statusCode': 200, 'body': json.dumps('Hello from Lambda!') }