-
Notifications
You must be signed in to change notification settings - Fork 444
docs(build_recipes): add performance optimization page #7197
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
+94
−0
Merged
Changes from 3 commits
Commits
Show all changes
5 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
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,34 @@ | ||
--- | ||
title: Performance Optimization | ||
description: Optimize Lambda functions for better performance and reduced costs | ||
--- | ||
|
||
<!-- markdownlint-disable MD043 --> | ||
|
||
Optimize your Lambda functions for better performance, reduced cold start times, and lower costs. These techniques help minimize package size, improve startup speed, and reduce memory usage. | ||
|
||
## Reduce cold start times | ||
|
||
1. **Minimize package size** by excluding unnecessary files | ||
2. **Use compiled dependencies** when possible | ||
3. **Leverage Lambda SnapStart** or **Provisioned concurrency** when possible | ||
|
||
## Build optimization | ||
|
||
=== "Exclude unnecessary files" | ||
|
||
```bash | ||
--8<-- "examples/build_recipes/build_optimization/optimize-package.sh" | ||
``` | ||
|
||
=== "Layer optimization" | ||
|
||
```bash | ||
--8<-- "examples/build_recipes/build_optimization/optimize-layer.sh" | ||
``` | ||
|
||
=== "Advanced optimization with debug symbol removal" | ||
|
||
```bash | ||
--8<-- "examples/build_recipes/build_optimization/optimize-advanced.sh" | ||
``` |
26 changes: 26 additions & 0 deletions
26
examples/build_recipes/build_optimization/optimize-advanced.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,26 @@ | ||
#!/bin/bash | ||
|
||
# Remove unnecessary files | ||
find build/ -name "*.pyc" -delete | ||
find build/ -name "__pycache__" -type d -exec rm -rf {} + | ||
find build/ -name "*.dist-info" -type d -exec rm -rf {} + | ||
find build/ -name "tests" -type d -exec rm -rf {} + | ||
find build/ -name "test_*" -delete | ||
|
||
# Remove debug symbols from compiled extensions | ||
find build/ -name "*.so" -exec strip --strip-debug {} \; 2>/dev/null || true | ||
find build/ -name "*.so.*" -exec strip --strip-debug {} \; 2>/dev/null || true | ||
|
||
# Remove additional bloat from common packages | ||
rm -rf build/*/site-packages/*/tests/ | ||
rm -rf build/*/site-packages/*/test/ | ||
rm -rf build/*/site-packages/*/.git/ | ||
rm -rf build/*/site-packages/*/docs/ | ||
rm -rf build/*/site-packages/*/examples/ | ||
rm -rf build/*/site-packages/*/*.md | ||
rm -rf build/*/site-packages/*/*.rst | ||
rm -rf build/*/site-packages/*/*.txt | ||
|
||
# Calculate size reduction | ||
echo "📊 Package optimization completed" | ||
du -sh build/ 2>/dev/null || echo "✅ Advanced optimization applied" |
18 changes: 18 additions & 0 deletions
18
examples/build_recipes/build_optimization/optimize-layer.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 | ||
|
||
# Create optimized layer structure | ||
mkdir -p layer/python/ | ||
|
||
# Install only production dependencies | ||
pip install aws-lambda-powertools[all] -t layer/python/ --no-deps | ||
pip install pydantic -t layer/python/ --no-deps | ||
|
||
# Remove unnecessary files from layer | ||
find layer/ -name "*.pyc" -delete | ||
find layer/ -name "__pycache__" -type d -exec rm -rf {} + | ||
find layer/ -name "tests" -type d -exec rm -rf {} + | ||
|
||
# Create layer zip | ||
cd layer && zip -r ../optimized-layer.zip . && cd .. | ||
|
||
echo "✅ Optimized layer created: optimized-layer.zip" |
14 changes: 14 additions & 0 deletions
14
examples/build_recipes/build_optimization/optimize-package.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 | ||
|
||
# Remove unnecessary files to reduce package size | ||
find build/ -name "*.pyc" -delete | ||
find build/ -name "__pycache__" -type d -exec rm -rf {} + | ||
find build/ -name "*.dist-info" -type d -exec rm -rf {} + | ||
find build/ -name "tests" -type d -exec rm -rf {} + | ||
find build/ -name "test_*" -delete | ||
|
||
# Remove documentation and examples | ||
find build/ -name "docs" -type d -exec rm -rf {} + | ||
find build/ -name "examples" -type d -exec rm -rf {} + | ||
|
||
echo "✅ Package optimized" |
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.