11

I am creating a DeepLens project to recognise people, when one of select group of people are scanned by the camera.

The project uses a lambda, which processes the images and triggers the 'rekognition' aws api.

  • When I trigger the API from my local machine - I get a good response

  • When I trigger the API from AWS console - I get failed response

Problem

After much digging, I found that the 'boto3' (AWS python library) is of version:

  • 1.9.62 - on my local machine

  • 1.8.9 - on AWS console

Question

Can I upgrade the 'boto3' library version on the AWS lambda console ?? If so, how ?

Deep
  • 673
  • 1
  • 10
  • 23

3 Answers3

10

If you don't want to package a more recent boto3 version with you function, you can download boto3 with each invocation of the Lambda. Remember that /tmp/ is the directory that Lambda will allow you to download to, so you can use this to temporarily download boto3:

import sys
from pip._internal import main

main(['install', '-I', '-q', 'boto3', '--target', '/tmp/', '--no-cache-dir', '--disable-pip-version-check'])
sys.path.insert(0,'/tmp/')

import boto3
from botocore.exceptions import ClientError

def handler(event, context):
    print(boto3.__version__)
user1998671
  • 125
  • 1
  • 6
4

You can achieve the same with either Python function with dependencies or with a Virtual Environment.

These are the available options other than that you also try to contact Amazon team if they can help you with up-gradation.

Shivang Agarwal
  • 1,825
  • 1
  • 14
  • 19
  • Thanks, but the new deployment fails without any errors. Meaning custom runtime debugging is trickier compared to the provided runtime. – Deep Dec 12 '18 at 13:28
  • 1
    Note that if you're using the Serverless Framework and `serverless-python-requirements` plugin, it won't deploy `boto3` and `botocore` by default even if they are in your requirements. You need to set the `noDeploy` parameter in the configuration and not put `boto3` and `botocore` in it – nbarraille Mar 27 '19 at 07:58
1

I know, you're asking for a solution through Console, but this is not possible (as of my knowledge).

To solve this you need to provide the boto3 version you require to your lambda (either with the solution from user1998671 or with what Shivang Agarwal is proposing). A third solution is to provide the required boto3 version as a layer for the lambda. The big advantage of the layer is that you can re-use it for all your lambdas.
This can be achieved by following the guide from AWS (the following is mainly copied from the linked guide from AWS):

IMPORTANT: Make sure to adjust boto3-mylayer with a for you suitable name.

  1. Create a lib folder by running the following command:
LIB_DIR=boto3-mylayer/python
mkdir -p $LIB_DIR
  1. Install the library to LIB_DIR by running the following command:
pip3 install boto3 -t $LIB_DIR
  1. Zip all the dependencies to /tmp/boto3-mylayer.zip by running the following command:
cd boto3-mylayer
zip -r /tmp/boto3-mylayer.zip .
  1. Publish the layer by running the following command:
aws lambda publish-layer-version --layer-name boto3-mylayer --zip-file fileb:///tmp/boto3-mylayer.zip

The command returns the new layer's Amazon Resource Name (ARN), similar to the following one:

arn:aws:lambda:region:$ACC_ID:layer:boto3-mylayer:1

To attach this layer to your lambda execute the following:

aws lambda update-function-configuration --function-name <name-of-your-lambda> --layers <layer ARN>

To verify the boto version in your lambda you can simply add the following two print commands in your lambda:

print(boto3.__version__)
print(botocore.__version__)
Michael Aicher
  • 629
  • 12
  • 14