generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 456
docs(build_recipes): add troubleshooting page #7195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --- | ||
| title: Troubleshooting | ||
| description: Common issues and solutions when building Lambda packages | ||
| --- | ||
|
|
||
| <!-- markdownlint-disable MD043 --> | ||
|
|
||
| ## Common issues and solutions | ||
|
|
||
| This section covers the most frequent issues encountered when building and deploying Lambda functions with Powertools for AWS Lambda (Python). Each issue includes symptoms to help identify the problem and practical solutions with working code examples. | ||
|
|
||
| ### Package size issues | ||
|
|
||
| ???+ warning "Lambda deployment package too large (>50MB unzipped)" | ||
| **Symptoms:** | ||
| - `RequestEntityTooLargeException` during deployment | ||
| - Slow cold starts | ||
| - High memory usage | ||
|
|
||
| **Solutions:** | ||
| ```bash | ||
| --8<-- "examples/build_recipes/troubleshooting/optimize-package-size.sh" | ||
| ``` | ||
|
|
||
| ### Import and runtime errors | ||
|
|
||
| ???+ error "ModuleNotFoundError or ImportError" | ||
| **Symptoms:** | ||
| - `ModuleNotFoundError: No module named 'aws_lambda_powertools'` | ||
| - Function fails at runtime with import errors | ||
|
|
||
| **Solutions:** | ||
| ```bash | ||
| --8<-- "examples/build_recipes/troubleshooting/debug-import-errors.sh" | ||
| ``` | ||
|
|
||
| ???+ error "Architecture mismatch errors" | ||
| **Symptoms:** | ||
| - `ImportError: /lib64/libc.so.6: version GLIBC_2.XX not found` | ||
| - Compiled extensions fail to load | ||
|
|
||
| **Solutions:** | ||
| ```bash | ||
| --8<-- "examples/build_recipes/troubleshooting/fix-architecture-mismatch.sh" | ||
| ``` | ||
|
|
||
| ### Performance issues | ||
|
|
||
| ???+ warning "Slow cold starts" | ||
| **Symptoms:** | ||
| - High initialization duration in CloudWatch logs | ||
| - Timeouts on first invocation | ||
|
|
||
| **Solutions:** | ||
| ```bash | ||
| --8<-- "examples/build_recipes/troubleshooting/optimize-cold-starts.sh" | ||
| ``` | ||
|
|
||
| ### Build and deployment issues | ||
|
|
||
| ???+ error "Build inconsistencies across environments" | ||
| **Symptoms:** | ||
| - Works locally but fails in CI/CD | ||
| - Different behavior between team members | ||
|
|
||
| **Solutions:** | ||
| ```bash | ||
| --8<-- "examples/build_recipes/troubleshooting/fix-build-inconsistencies.sh" | ||
| ``` | ||
|
|
||
| ???+ error "Layer compatibility issues" | ||
| **Symptoms:** | ||
| - Layer not found or incompatible runtime | ||
| - Version conflicts between layer and function dependencies | ||
|
|
||
| **Solutions:** | ||
| ```bash | ||
| --8<-- "examples/build_recipes/troubleshooting/fix-layer-compatibility.sh" | ||
| ``` |
12 changes: 12 additions & 0 deletions
12
examples/build_recipes/troubleshooting/debug-import-errors.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| # 1. Verify dependencies are in the package | ||
| unzip -l lambda-package.zip | grep powertools | ||
|
|
||
| # 2. Check Python path in Lambda | ||
| python -c "import sys; print(sys.path)" | ||
|
|
||
| # 3. Ensure platform compatibility | ||
| pip install --platform manylinux2014_x86_64 --only-binary=:all: aws-lambda-powertools[all] | ||
|
|
||
| # 4. Test imports locally | ||
| cd build && python -c "from aws_lambda_powertools import Logger; print('OK')" |
8 changes: 8 additions & 0 deletions
8
examples/build_recipes/troubleshooting/fix-architecture-mismatch.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
| # Use Docker with Lambda base image | ||
| docker run --rm -v "$PWD":/var/task public.ecr.aws/lambda/python:3.13 \ | ||
| pip install aws-lambda-powertools[all] -t /var/task/ | ||
|
|
||
| # Or force Linux-compatible wheels | ||
| pip install --platform manylinux2014_x86_64 --implementation cp \ | ||
| --python-version 3.13 --only-binary=:all: aws-lambda-powertools[all] |
18 changes: 18 additions & 0 deletions
18
examples/build_recipes/troubleshooting/fix-build-inconsistencies.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/bin/bash | ||
| # 1. Use lock files for reproducible builds | ||
| # Poetry: poetry.lock | ||
| # uv: uv.lock | ||
| # pip: requirements.txt with pinned versions | ||
|
|
||
| # 2. Use Docker for consistent build environment | ||
| docker run --rm -v "$PWD":/app -w /app python:3.13-slim \ | ||
| bash -c "pip install -r requirements.txt -t build/" | ||
|
|
||
| # 3. Pin all tool versions | ||
| pip==24.0 | ||
| poetry==1.8.0 | ||
| uv==0.1.0 | ||
|
|
||
| # 4. Use same Python version everywhere | ||
| python-version: '3.13' # In CI/CD | ||
| python = "^3.13" # In pyproject.toml |
12 changes: 12 additions & 0 deletions
12
examples/build_recipes/troubleshooting/fix-layer-compatibility.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| # 1. Use correct layer ARN for your region and Python version | ||
| # Check: https://docs.powertools.aws.dev/lambda/python/latest/#lambda-layer | ||
|
|
||
| # 2. Verify layer compatibility | ||
| aws lambda get-layer-version \ | ||
| --layer-name AWSLambdaPowertoolsPythonV3-python313-x86_64 \ | ||
| --version-number 22 | ||
|
|
||
| # 3. Avoid version conflicts | ||
| # Don't include Powertools for AWS in deployment package if using layer | ||
| pip install pydantic requests -t build/ # Exclude powertools |
13 changes: 13 additions & 0 deletions
13
examples/build_recipes/troubleshooting/optimize-cold-starts.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/bin/bash | ||
| # 1. Optimize package size (see above) | ||
|
|
||
| # 2. Use public Powertools for AWS layer | ||
| # Layer ARN: arn:aws:lambda:region:017000801446:layer:AWSLambdaPowertoolsPythonV3-python313-x86_64:1 | ||
|
|
||
| # 3. Enable provisioned concurrency for critical functions | ||
| aws lambda put-provisioned-concurrency-config \ | ||
| --function-name my-function \ | ||
| --provisioned-concurrency-config ProvisionedConcurrencyCount=10 | ||
|
|
||
| # 4. Minimize imports in handler | ||
| # Import only what you need, avoid heavy imports at module level | ||
14 changes: 14 additions & 0 deletions
14
examples/build_recipes/troubleshooting/optimize-package-size.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| # 1. Use Lambda Layers for heavy dependencies | ||
| pip install aws-lambda-powertools[all] -t layers/powertools/python/ | ||
|
|
||
| # 2. Remove unnecessary files | ||
| find build/ -name "*.pyc" -delete | ||
| find build/ -name "__pycache__" -type d -exec rm -rf {} + | ||
| find build/ -name "tests" -type d -exec rm -rf {} + | ||
|
|
||
| # 3. Strip debug symbols from compiled libraries | ||
| find build/ -name "*.so" -exec strip --strip-debug {} \; | ||
|
|
||
| # 4. Use container images for very large packages | ||
| # Deploy as container image instead of ZIP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.