Skip to content

docs(build_recipes): add Lambda build recipes for pip, poetry, uv, SAM, CDK, and pants #7149

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

Closed
wants to merge 9 commits into from

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #3518

Summary

This PR introduces a Build Recipes documentation that addresses challenges when developers are packaging Lambda functions with Python and compiled libraries, especially. Rather than leaving developers to figure out packaging on their own, we now provide recipes for every major Python build tool, complete with working examples, troubleshooting guides, and production-ready CI/CD configurations.

Changes

  • docs/build_recipes.md - Complete build recipes guide
  • Covers 6 major build tools: pip, poetry, uv, SAM, CDK, pants
  • Cross-platform build strategies with Docker and platform-specific installations
  • Performance optimization techniques including debug symbol stripping
  • Comprehensive troubleshooting section with categorized solutions

Working Examples:

  • examples/build_recipes/pip/ - Basic and advanced pip configurations with layers
  • examples/build_recipes/poetry/ - Poetry with Docker builds and lock files
  • examples/build_recipes/uv/ - Fast uv-based builds with reproducible environments
  • examples/build_recipes/sam/ - SAM templates (no-layers, with-layers, multi-env)
  • examples/build_recipes/cdk/ - CDK stacks (basic and multi-stack architectures)
  • examples/build_recipes/pants/ - Pants build system for monorepos

CI/CD Integration:

  • examples/build_recipes/cicd/github-actions/ - GitHub Actions workflows
  • examples/build_recipes/cicd/codebuild/ - AWS CodeBuild example

User experience

Please share what the user experience looks like before and after this change

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team as a code owner August 11, 2025 23:36
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 11, 2025

Not all issues are linked correctly.

Please link each issue to the PR either manually or using a closing keyword in the format fixes #<issue-number> format.

If mentioning more than one issue, separate them with commas: i.e. fixes #<issue-number-1>, closes #<issue-number-2>.

@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation internal Maintenance changes labels Aug 11, 2025
@leandrodamascena leandrodamascena self-assigned this Aug 11, 2025
@leandrodamascena leandrodamascena linked an issue Aug 11, 2025 that may be closed by this pull request
1 task
@github-actions github-actions bot removed the internal Maintenance changes label Aug 11, 2025
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

2 similar comments
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@boring-cyborg boring-cyborg bot added the internal Maintenance changes label Aug 11, 2025
@github-actions github-actions bot removed the internal Maintenance changes label Aug 11, 2025
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@boring-cyborg boring-cyborg bot added the internal Maintenance changes label Aug 11, 2025
@github-actions github-actions bot removed the internal Maintenance changes label Aug 11, 2025
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

Copy link

codecov bot commented Aug 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.35%. Comparing base (bcc1888) to head (8c18dbf).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #7149   +/-   ##
========================================
  Coverage    96.35%   96.35%           
========================================
  Files          275      275           
  Lines        12980    12980           
  Branches       965      965           
========================================
  Hits         12507    12507           
  Misses         366      366           
  Partials       107      107           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@phipag phipag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general question: With uv for example I would add a zip deployment in my IaC tool?

@boring-cyborg boring-cyborg bot added the internal Maintenance changes label Aug 12, 2025
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@github-actions github-actions bot removed the internal Maintenance changes label Aug 12, 2025
@boring-cyborg boring-cyborg bot added the internal Maintenance changes label Aug 12, 2025
@leandrodamascena
Copy link
Contributor Author

A general question: With uv for example I would add a zip deployment in my IaC tool?

Hi @phipag, I'm not sure I understand your question, but I assume you're asking about the assets uv can create, right? Among other things, uv was designed exclusively to compile/package code into a zip file or distribution wheel. It then packages the code with its dependencies and creates the asset (zip file in this case). With this asset, you can deploy it however you want.

Pls let me know if this answer is enough

@phipag
Copy link

phipag commented Aug 12, 2025

A general question: With uv for example I would add a zip deployment in my IaC tool?

Hi @phipag, I'm not sure I understand your question, but I assume you're asking about the assets uv can create, right? Among other things, uv was designed exclusively to compile/package code into a zip file or distribution wheel. It then packages the code with its dependencies and creates the asset (zip file in this case). With this asset, you can deploy it however you want.

Pls let me know if this answer is enough

Yes, thanks. This is what I meant.

@leandrodamascena
Copy link
Contributor Author

Will review this PR? Please read this comments:

1/ You don't need to test every script; I've tested it extensively and it's working as expected. But if you want, please go ahead.
2/ Focus on the docs/recipes_build.md file. The text, possible typos, messaging improvements and other things.
3/ I included the entire examples/build_recipes as excluded int he CloudFormation lint because there is a bug that causes these pre-commit hooks to not be able to differentiate whether it is a CloudFormation yaml or a GitHub action, for example.

@leandrodamascena
Copy link
Contributor Author

leandrodamascena commented Aug 12, 2025

Hi @phipag @sthulb @dreamorosi @svozza, I asked you for a review on this PR. Please read this comment before reviewing: #7149 (comment)

@leandrodamascena leandrodamascena requested review from svozza and removed request for anafalcao August 12, 2025 09:15
@boring-cyborg boring-cyborg bot added the internal Maintenance changes label Aug 12, 2025
@github-actions github-actions bot removed the internal Maintenance changes label Aug 12, 2025
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

powertools_layer = _lambda.LayerVersion.from_layer_version_arn(
self,
"PowertoolsLayer",
layer_version_arn="arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPythonV3-python313-x86_64:1",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the latest layer here?

@boring-cyborg boring-cyborg bot added the internal Maintenance changes label Aug 12, 2025
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@github-actions github-actions bot removed the internal Maintenance changes label Aug 12, 2025
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more time to pull the branch & render the docs, but I've left some comments on the files I was able to review on here.

cd build && zip -r ../lambda-deployment.zip . && cd ..

- name: Upload artifact
uses: actions/upload-artifact@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use hashes wherever possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good point! The idea of not using hashes here was to avoid more dependabot bumps, but I think this will decrease our scorecard score. Thanks for flagging that, I'll change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking more of sharing/encouraging best practices in the examples we give customers.

If you want to avoid Dependabot spam on these, you can add a section to its config to explicitly exclude this (and other) files.

powertools_layer = _lambda.LayerVersion.from_layer_version_arn(
self,
"PowertoolsLayer",
layer_version_arn="arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPythonV3-python313-x86_64:1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an old version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! @svozza flagged that and I'll update

)

# Lambda Function
api_function = _lambda.Function(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the Python function package in CDK that does the packaging for you?

|------|------------|
| **Deployment Package** | A ZIP archive or container image containing your Lambda function code and all its dependencies, ready for deployment to AWS Lambda |
| **Lambda Layer** | A ZIP archive containing libraries, custom runtimes, or other function dependencies that can be shared across multiple Lambda functions |
| **Build Tool** | Software that automates the process of compiling, packaging, and preparing your code for deployment (e.g., pip, poetry, uv, pants) |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| **Build Tool** | Software that automates the process of compiling, packaging, and preparing your code for deployment (e.g., pip, poetry, uv, pants) |
| **Build Tool** | Software that automates the process of compiling, packaging, and preparing your code for deployment (e.g., `pip`, `poetry`, `uv`, `pants`) |

| **Lambda Layer** | A ZIP archive containing libraries, custom runtimes, or other function dependencies that can be shared across multiple Lambda functions |
| **Build Tool** | Software that automates the process of compiling, packaging, and preparing your code for deployment (e.g., pip, poetry, uv, pants) |
| **Dependency Manager** | Tool responsible for resolving, downloading, and managing external libraries your project depends on |
| **Lock File** | A file that records the exact versions of all dependencies used in your project, ensuring reproducible builds (e.g., poetry.lock, uv.lock) |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| **Lock File** | A file that records the exact versions of all dependencies used in your project, ensuring reproducible builds (e.g., poetry.lock, uv.lock) |
| **Lock File** | A file that records the exact versions of all dependencies used in your project, ensuring reproducible builds (e.g., `poetry.lock`, `uv.lock`) |


### CDK

**AWS CDK (Cloud Development Kit)** allows you to define cloud infrastructure using familiar programming languages like Python, TypeScript, or Java. It provides type safety, IDE support, and the ability to create reusable constructs, making it perfect for complex infrastructure requirements and teams that prefer code over YAML.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**AWS CDK (Cloud Development Kit)** allows you to define cloud infrastructure using familiar programming languages like Python, TypeScript, or Java. It provides type safety, IDE support, and the ability to create reusable constructs, making it perfect for complex infrastructure requirements and teams that prefer code over YAML.
The **AWS CDK (Cloud Development Kit)** allows you to define cloud infrastructure using familiar programming languages like Python, TypeScript, or Java. It provides type safety, IDE support, and the ability to create reusable constructs, making it perfect for complex infrastructure requirements and teams that prefer code over YAML.

### Best Practices for CI/CD

1. **Use Linux runners** (ubuntu-latest) to ensure Lambda compatibility
2. **Cache dependencies** to speed up builds (uv, poetry cache, pip cache)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. **Cache dependencies** to speed up builds (uv, poetry cache, pip cache)
2. **Cache dependencies** to speed up builds (`uv`, `poetry cache`, `pip cache`)

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content is good, but I think we can do better when it comes to structure and placement, right now it's a wall of text that can be hard to navigate and digest both for humans and LLMs.

From a doc architecture perspective, I don't think this should be a separate tab but instead just be a collapsible section on the left-side menu.

Personally, I'd move a couple things around and have like:

  • Homepage

  • Install/Getting Started (future PR)

  • Changelog

  • Tutorial

  • Workshop

  • Build recipes (this PR - section is collapsed by default, below sections are revealed only when clicking)

    • index.md Getting Started (includes intro, key benefits, Terminology, and Getting Started sections)
    • Cross Platform
    • Build with pip
    • Build with poetry
    • Build with uv
    • Build with SAM
    • Build with CDK
    • Build with Pants
    • Performance optimization
    • CI/CD integration
    • Troubleshooting
  • Features

    • Tracer
    • Logger
    • ...
  • Environment variables (future PR)

  • Upgrade guide

  • Community content (renamed from We Made This)

  • Roadmap

  • Changelog

  • Resources (LLMs)


This structure would also basically break down each section in its own page - since in most cases imo for this topic you rarely want to read top to bottom, but are interested in a specific area/section, this way it's easier to consume/save/share/read for both humans and LLMs.

@leandrodamascena
Copy link
Contributor Author

The content is good, but I think we can do better when it comes to structure and placement, right now it's a wall of text that can be hard to navigate and digest both for humans and LLMs.

From a doc architecture perspective, I don't think this should be a separate tab but instead just be a collapsible section on the left-side menu.

Personally, I'd move a couple things around and have like:

  • Homepage

  • Install/Getting Started (future PR)

  • Changelog

  • Tutorial

  • Workshop

  • Build recipes (this PR - section is collapsed by default, below sections are revealed only when clicking)

    • index.md Getting Started (includes intro, key benefits, Terminology, and Getting Started sections)
    • Cross Platform
    • Build with pip
    • Build with poetry
    • Build with uv
    • Build with SAM
    • Build with CDK
    • Build with Pants
    • Performance optimization
    • CI/CD integration
    • Troubleshooting
  • Features

    • Tracer
    • Logger
    • ...
  • Environment variables (future PR)

  • Upgrade guide

  • Community content (renamed from We Made This)

  • Roadmap

  • Changelog

  • Resources (LLMs)

This structure would also basically break down each section in its own page - since in most cases imo for this topic you rarely want to read top to bottom, but are interested in a specific area/section, this way it's easier to consume/save/share/read for both humans and LLMs.

This is great feedback! I was thinking this document was too information-heavy, but I'm not sure about one thing: this way, won't we take up too much space for Features meny? Maybe these Features sections should always be visible in the menu.

Maybe a tab in the top menu isn't the best idea, I agree. But what do you think about this feature issue? I can do a test and see the experience

@dreamorosi
Copy link
Contributor

This is great feedback! I was thinking this document was too information-heavy, but I'm not sure about one thing: this way, won't we take up too much space for Features meny? Maybe these Features sections should always be visible in the menu.

Maybe a tab in the top menu isn't the best idea, I agree. But what do you think about this feature issue? I can do a test and see the experience

I was thinking of having a single item called "Build recipes" that is closed by default like this image below, so that it takes only one space:

image

its sub-items would show only if you click on it.

And yes, I'd leave "Features" as always visible for now.

@leandrodamascena
Copy link
Contributor Author

This is great feedback! I was thinking this document was too information-heavy, but I'm not sure about one thing: this way, won't we take up too much space for Features meny? Maybe these Features sections should always be visible in the menu.
Maybe a tab in the top menu isn't the best idea, I agree. But what do you think about this feature issue? I can do a test and see the experience

I was thinking of having a single item called "Build recipes" that is closed by default like this image below, so that it takes only one space:

image its sub-items would show only if you click on it.

And yes, I'd leave "Features" as always visible for now.

Hey @dreamorosi I'm probably doing something stupid, but I can't make it collapse under Homepage level, but if I add under Features it works. I probably need help here.

image image

@boring-cyborg boring-cyborg bot added the internal Maintenance changes label Aug 12, 2025
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@github-actions github-actions bot removed the internal Maintenance changes label Aug 12, 2025
Copy link

@leandrodamascena
Copy link
Contributor Author

I'm closing this PR because I'll be opening other smaller ones to make reviewing easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: Packaging Assets with Pants
4 participants