Tonight I was working on a side project and ran into an issue I had not run into previously. The boto3 library used by the AWS Lambda python runtime was out of date compared to my own local environment.
This issue was raised over at the boto3 github site. Turns out I ran into the exact same thing.
Thankfully, AWS Lambda service allows you to upload your own libraries as layers that are then attached to the Lambda function. AWS (as usual) provides pretty straight-forward documentation on deploying a layer, and specifically an updated boto3 layer, full instructions are available here.
First, open a CloudShell console and run the following commands:
LIB_DIR=boto3-mylayer/python mkdir -p $LIB_DIR pip3 install boto3 -t $LIB_DIR cd boto3-mylayer zip -r /tmp/boto3-mylayer.zip . aws lambda publish-layer-version --layer-name boto3-mylayer --zip-file fileb:///tmp/boto3-mylayer.zip <take note of the versionArn, it's used in the next step> aws lambda update-function-configuration --function-name MY_FUNCTION --layers LAYER_ARN
Once the layer is uploaded and applied, you’ll be able to properly with the latest boto3 library installed. I won’t call out AWS all that much for not being current with the boto3 library, I’d assume they favor stability of the underlying Ec2 instances as opposed to always running the latest code with potential problems.
Hope this helps someone in the future.