Anthony Kong
Anthony Kong

Reputation: 40834

How to add boto library to an python-based AWS lambda function?

I want to create a lambda function in python3.7 that it will use boto to perform some AWS query.

enter image description here

The function is very simple. I added import boto to the simple vanilla template to try out how to enable boto.

import json

import boto

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Needless to say, it fails:

Response:
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'boto'",
  "errorType": "Runtime.ImportModuleError"
}

So how can I add boto to my code?

I have checked out Layers and it is empty.

enter image description here

I think I can create on by uploading a zip file. But what should I put inside the zip file? What sort of directory structure is Lambda expecting?

Upvotes: 0

Views: 6963

Answers (2)

Murali Allada
Murali Allada

Reputation: 22948

boto has been deprecated. You should be using boto3.

Import boto3

Upvotes: 3

mkrana
mkrana

Reputation: 430

This is like adding additional dependencies to aws lambda.

Please follow document to add boto package.

Upvotes: 1

Related Questions