As member of the new PaaS generation, AWS Lambda provides a “serverless” computing platform: the developer no longer has to worry about capacity planning, code deploys, server updates, etc., basically a step closer to the “NoOps” controversial Nirvana.

When python support was added to AWS Lambda, I wondered if it would be possible to use it replicate some of the Ansible Tower functionality: features like running on-demand playbooks or call ansible from cloud-init.

According to AWS documentation, a deployment package is required. The first step to create it is installing ansible into a target directory: lambda, as seen below.

pip install ansible==1.9.4 -t lambda

Now let’s call ansible using the python API:

Zip the contents, so as to create the deployment package:

pushd lambda; \

zip -r ../lambda.zip ../ansible_lambda.py ../test.yml * ; \

popd

Configure a AWS Lambda function:

However, when testing, the following message appears:

So what happened? What did we do wrong? According to the AWS Lambda FAQ:

Q: What if I need scratch space on disk for my AWS Lambda function?A: Each Lambda function receives 500MB of non-persistent disk space in its own /tmp directory.

In light of these instructions, we’ll have to take a step back and perform a tweak in the code:

After packaging and uploading the new code: