1

How to create a simple lambda function in Python

This seems example for NodeJS but looking for a Python version..

aws lambda create-function --function-name helloworld \
--zip-file fileb://function.zip --handler index.handler --runtime nodejs8.10 \
--role arn:aws:iam::123456789012:role/lambda-cli-role
{
    "FunctionName": "helloworld",
    "CodeSize": 351,
    "MemorySize": 128,
    "FunctionArn": "function-arn",
    "Handler": "index.handler",
    "Role": "arn:aws:iam::account-id:role/LambdaExecRole",
    "Timeout": 3,
    "LastModified": "2015-04-07T22:02:58.854+0000",
    "Runtime": "nodejs8.10",
    "Description": ""
}

1 Answer 1

3

You can use the same CLI options but specify the python runtime as well as include a python application in zip file format.

aws lambda create-function --function-name helloworld \
--zip-file fileb://test.zip \
--handler lambda_function.lambda_handler \
--runtime python3.7 \
--role arn:aws:iam::XXXX:role/CustomLambdaRoleARN 

CLI Output:
{
   "FunctionName": "helloworld",
   "FunctionArn": "arn:aws:lambda:us-west-2:XXXXXX:function:helloworld",
   "Runtime": "python3.7",
   "Role": "arn:aws:iam::XXXX:role/CustomLambdaRoleARN",
   "Handler": "lambda_function.lambda_handler",
   "CodeSize": 236,
   "Description": "",
   "Timeout": 3,
   "MemorySize": 128,
   "LastModified": "2019-04-23T04:25:33.052+0000",
   "CodeSha256": "5Gm3xdLGxELEIboaATKL7pr4sxrjNV1kuT9l9kpFG0g=",
   "Version": "$LATEST",
   "TracingConfig": {
       "Mode": "PassThrough"
   },
   "RevisionId": "3f18add5-d347-4754-83e5-61dfdeabda9a"

If you need help building a lambda application zip file, see this walk through. https://geektopia.tech/post.php?blogpost=Create_Lambda_Package_Python

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.