- Newest
- Most votes
- Most comments
This issue appears to be related to a version conflict between the AWS SDK (boto3/botocore) included in the Python 3.12 Lambda runtime and the version being imported from your Lambda Layer.
AWS Lambda Python runtimes come with pre-installed versions of boto3 and botocore. When you add a layer that includes its own version of these libraries, you can encounter import conflicts like the one you're experiencing. The Lambda runtime's built-in libraries are typically loaded first, which can cause conflicts when your layer's code expects a different version.
The error "cannot import name 'DEFAULT_CHECKSUM_ALGORITHM' from 'botocore.httpchecksum'" suggests that the runtime is using a version of botocore that doesn't have this attribute, even though your layer includes a newer version that does.
To resolve this issue, you have a few options:
-
Package the required boto3/botocore versions directly with your function code rather than in the layer. This can help ensure your function uses the versions you specify.
-
Modify your import path to explicitly use the versions from your layer by manipulating the Python path at runtime.
-
Check the exact version of boto3/botocore in your Lambda environment by creating a simple function that prints the versions:
import boto3 import botocore def lambda_handler(event, context): print(f'boto3 version: {boto3.__version__}') print(f'botocore version: {botocore.__version__}')
- Consider using a container image for your Lambda function instead of layers if you need precise control over the environment and dependencies.
Architecture mismatches can also cause similar issues. Make sure that any compiled extensions in your layer are compatible with the Lambda runtime architecture.
For AWS X-Ray SDK specifically, you might need to ensure that all its dependencies are properly included and that there are no conflicts with the runtime's built-in libraries.
Sources
Building Lambda functions with Python - AWS Lambda
Troubleshooting - Powertools for AWS Lambda (Python)
answered 9 months ago
Relevant content
asked 2 years ago
asked 3 years ago
