Create a Python package for Lambda

In some cases the modules available in boto3 do not provide those which might be required in a project to let Lambda act as desired.

Preparing a function package

Create a folder and inside the folder install the modules that will be packed. Pip is just helpful in this case. Afterwards do a recursive zip inside the folder. In my case I had to install the DataStax Cassandra drivers.

sudo pip3 install cassandra-driver -t .
cd ./aws_lambda
zip -r aws_lambda ./*

Now zip file need to be uploaded into the Lambda function – depends on the size of the package it will not be able to get code shown in the editor insight the UI.

If everything else is set correctly a quick test should show if the function works and if modules can be loaded.

In this case a quick select has been executed to verify functionality.

cql = 'SELECT max_index_interval, min_index_interval, gc_grace_seconds, speculative_retry from tables LIMIT 1000'
session.row_factory = dict_factory

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: