Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/quality_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ permissions:

jobs:
quality_check:
runs-on: ubuntu-latest
runs-on: codebuild-${{ github.run_id }}-${{ github.run_attempt }}
strategy:
max-parallel: 5
matrix:
Expand Down
34 changes: 34 additions & 0 deletions docs/build_recipes/performance-optimization.md
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 examples/build_recipes/build_optimization/optimize-advanced.sh
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 examples/build_recipes/build_optimization/optimize-layer.sh
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 examples/build_recipes/build_optimization/optimize-package.sh
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"
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ nav:
- Build recipes:
- build_recipes/index.md
- Getting started: build_recipes/getting-started.md
- Performance optimization: build_recipes/performance-optimization.md
- CI/CD integration: build_recipes/cicd-integration.md
- Troubleshooting: build_recipes/troubleshooting.md
- Upgrade guide: upgrade.md
Expand Down Expand Up @@ -242,6 +243,7 @@ plugins:
Build recipes:
- build_recipes/index.md
- build_recipes/getting-started.md
- build_recipes/performance-optimization.md
- build_recipes/cicd-integration.md
- build_recipes/troubleshooting.md

Expand Down
Loading