Why am I getting "unknown service", "parameter validation failed", or "object has no attribute" errors with my Python (Boto 3) Lambda function?

Last updated: 2019-09-26

When I run my AWS Lambda function written in Python, I get an error such "unknown service", "parameter validation failed", or "object has no attribute". How do I fix these errors?

Short Description

These errors can occur when your Lambda function is configured to use one of the Lambda runtimes for Python and it tries to call a newer AWS service or the latest version of an AWS API. The version of the AWS SDK for Python (Boto 3) provided in the Lambda execution environment is not the latest version. It may be missing some arguments for some AWS services and APIs.

Create a layer that uses the latest version of Boto 3, and then add the layer to your function's configuration.


Note: These instructions are provided as a guideline, and they assume that you have a fresh working directory. For an existing working directory, you may need to upgrade botocore in order to upgrade Boto 3. Adjust the steps that you take as needed for your specific operating system and Python configuration.

Install pip and the AWS CLI

1.    If you haven't already, install pip3 for Python 3 packaging. If you have a previous version of pip, upgrade it.

2.    Install or upgrade the AWS Command Line Interface (AWS CLI) using pip3. The latest version of the AWS CLI includes the Lambda Layers API model.

Create a layer and add it to your Lambda function

Note: These commands are valid only for Linux/Unix/macOS systems. In the commands, replace boto3-mylayer with your preferred name for the lib folder and Lambda layer.

1.    Create a lib folder by running this command:

mkdir -p $LIB_DIR

2.    Install the library to LIB_DIR by running this command:

pip3 install boto3 -t $LIB_DIR

3.    Zip all the dependencies to /tmp/boto3-mylayer.zip by running this command:

cd boto3-mylayer
zip -r /tmp/boto3-mylayer.zip .

4.    Publish the layer by running this 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), which looks like this:


5.    Add the layer to your Lambda function's configuration by running this command:

Note: Replace myfunction with your function's name. Replace arn:aws:lambda:region:ACC_ID:layer:boto3-mylayer:1 with your layer's ARN.

aws lambda update-function-configuration --function-name myfunction --layers arn:aws:lambda:region:ACC_ID:layer:boto3-mylayer:1

All AWS services and arguments/keyword arguments are now available to your Lambda function.

Tip: Use print(boto3.__version__) and print(botocore.__version__) in your function code to confirm the version of Boto 3 and Botocore.

Did this article help you?

Anything we could improve?

Need more help?