Creating Lambda Function

Hi all, I am fairly new to localstack and aws. Does anyone know how can I create a simple lambda function and test it out on localstack on Docker? I went to read the documentation but it doesn’t show how to create and run a simple lambda function to know that the lambda is working. TIA!

1 Like

Hi @boogywumpy,

I would recommend reading up on Lambda functions on the AWS documentation pages for further information. This will help you learn how to make simple lambdas.

You can also find simple samples here Lambda sample applications – AWS Lambda (amazon.com).
They have simple step-by-step examples as well Building Lambda functions with Python – AWS Lambda (amazon.com)

For a quick lambda creation, you should be able to use the code below, which is a slightly modified version of the code found on our documentation page Lambda | Docs (localstack.cloud).

echo 'def handler(*args, **kwargs):' > /tmp/testlambda.py
echo '  print("Debug output from Lambda function")' >> /tmp/testlambda.py
(cd /tmp; zip testlambda.zip testlambda.py)
awslocal lambda create-function \
  --function-name func1 \
  --runtime python3.8 \
  --role arn:aws:iam::000000000000:role/lambda-role \
  --handler testlambda.handler \
  --timeout 30 \
  --zip-file fileb:///tmp/testlambda.zip

The logs from Lambda Function can be seen on our website (LocalStack) or you can use AWS CloudWatch Service and access is through the CLI.

In order to see the output directly in the LocalStack logs, you can set the variable DEBUG=1.