Reputation: 3789
I am facing weird issue with boto3 module in AWS. I am writing serverless framework with lambda functions. I am using aws boto3 module & running below code in python. Code execution is successful when running locally but fails with UnknownServiceError when executed in AWS.
client_api = boto3.client(service_name='apigatewaymanagementapi')
After a lot of research, I found that local boto3 version is 1.9.119 and AWS boto3 version is 1.9.42. I am not too sure if this is the root cause for the issue.
I have tried installing boto3 in venv target and used that reference. No matter what, code execution fails in AWS.
I have checked if there is a way I can update aws boto3 version.
I have also tried adding boto3 as external dependency in requirements file
I have also tried adding layers with boto3 zip and mapped to the lambda function.
Unfortunately none of the solutions works. Please suggest alternate solution for this issue.
Upvotes: 1
Views: 8568
Reputation: 542
You are correct, The boto3 library is older in lambda that what is on your local machine. You can create a lambda layer that includes a newer version of boto3 or package boto3 in your lambda package.
Here are some links with step by step instructions. They are installing pymysql, you can replace that with boto3. Otherwise the instructions are exactly the same.
https://geektopia.tech/post.php?blogpost=Create_Lambda_Layer_Python https://geektopia.tech/post.php?blogpost=Create_Lambda_Package_Python
Upvotes: 1
Reputation: 3893
This what The python 3.7 AWS lambda environment looks like at time of writing:
python: 3.7.2 (default, Mar 1 2019, 11:28:42)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)], boto3: 1.9.42, botocore: 1.12.42
By comparing botocore 1.12.42 (error) with 1.12.133 (working ok) I found that an outdated botocore in AWS Lambda is the culprit. One solution could be to include the latest botocore in your lambda package. For example using the the python requirements plugin:
serverless plugin install -n serverless-python-requirements
And creating a requirements.txt
file containing botocore==1.12.133
(instead of 1.12.133 you might want to use the latest version at the time you read this)
Upvotes: 0