How do I resolve "unknown service", "parameter validation failed", and "object has no attribute" errors from a Python (Boto3) Lambda function?
4 minute read
My Python (Boto3) AWS Lambda function returns "unknown service", "parameter validation failed", or "object has no attribute" errors.
A Python (Boto3) Lambda function that doesn't use the latest version of Boto3 might return any of the following errors:
parameter validation failed
object has no attribute
These errors occur when the function tries to call an AWS service or AWS API that requires the latest version of Boto3.
To resolve this issue, create a Lambda layer that uses the latest version of Boto3. You can do this manually, or you can use Docker. It's more efficient to upgrade your Lambda layer through Docker, and this makes sure that your binaries are correct for the Lambda operating system.
Important: The following procedures assume that you have the latest version of Botocore (on GitHub). If you don't have the latest version of Botocore, then you must upgrade Botocore before you can upgrade to the latest Boto3 version. Implement the resolution as needed for your specific and Python configuration.
It's a best practice to create a Lambda layer on the same operating system that your Lambda runtime is based on. For example, Python versions 3.8 and 3.9 are based on an Amazon Linux 2 Amazon Machine Image (AMI). However, Python 3.7 and Python 3.6 are based on the Amazon Linux AMI.
(Prerequisites) Install pip3 and the latest AWS CLI version
1. If you haven't already, then install pip3 for Python 3 packaging from the pip website.
If you have a previous version of pip, then upgrade it from the pip website.
Note: Replace boto3-mylayer with your package name. Replace REGION_NAME with your AWS Region. Also, include the compatible runtimes that you previously specified.
Manually create a Lambda layer that uses the latest Boto3 version
Important: The following AWS CLI commands work for Linux, Unix, and macOS operating systems. In each command, make sure that you replace boto3-mylayer with your preferred name for the lib folder and Lambda layer.
1. Create a lib folder:
mkdir -p $LIB_DIR
2. Install the library to LIB_DIR:
pip3 install boto3 -t $LIB_DIR
3. Zip all the dependencies to /tmp/boto3-mylayer.zip: