Add your description here
Project description
SAMWICH CLI
A sandwich :sandwich: for sam build
SAMWICH CLI is a tool that simplifies working with AWS Serverless Application Model (SAM) deployments, particularly focusing on dependency management and build processes for Python Lambda functions and layers.
Note: This project is in early development and may not be fully functional.
Table of Contents
Inspiration
Many python projects do not use requirements.txt files, but instead use pyproject.toml with poetry or uv. This tool is designed to help those projects by automatically generating a requirements.txt file from the pyproject.toml file, and then copying it to the appropriate locations for AWS Lambda functions and layers.
Also, using absolute python imports from the project root is not currently possible with AWS SAM (see https://github.com/aws/aws-sam-cli/issues/6593). This tool helps to maintain a consistent folder structure for your functions and layers, so the lambda functions can be individually packaged with the same folder structure as they are developed.
Installation
pipx install samwich-cli
Requirements
- Python 3.9 or higher
- Git (recommended for workspace detection)
Features
The SAMWICH CLI:
- Copies your
requirements.txtfile to the appropriate locations for Lambda functions and layers. - Executes
sam buildto build your AWS resources. - Updates the folder structure of your functions and layers to maintain consistency.
Example (with layers)
Project Structure
my-project/
├── layer/
│ └── lib/
│ └── utils.py
├── functions/
│ ├── sender/
│ │ └── app.py
│ └── receiver/
│ └── app.py
├── pyproject.toml
└── uv.lock
SAM Template
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: My SAM Application
Resources:
SenderFunction:
Type: AWS::Serverless::Function
Properties:
Handler: functions.sender.app.lambda_handler
Runtime: python3.12
CodeUri: functions/sender/
Layers:
- !Ref MyLayer
ReceiverFunction:
Type: AWS::Serverless::Function
Properties:
Handler: functions.receiver.app.lambda_handler
Runtime: python3.12
CodeUri: functions/receiver/
Layers:
- !Ref MyLayer
MyLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: MyLayer
ContentUri: layer/
CompatibleRuntimes:
- python3.12
Metadata:
BuildMethod: python3.12
Resulting Structure
.aws-sam/
├── build/
│ ├── SenderFunction/
│ │ └── functions/
│ | └── sender/
│ | └── app.py
│ ├── ReceiverFunction/
│ │ └── functions/
│ | └── receiver/
| | └── app.py
│ └── MyLayer/
│ └── python/
│ ├── requirements.txt
│ ├── < project dependencies >
│ └── layer/
│ └── lib/
│ └── utils.py
## Example (without layers)
### Project Structure
my-project/ ├── functions/ │ ├── sender/ │ │ └── app.py │ └── receiver/ │ └── app.py ├── pyproject.toml └── uv.lock
### SAM Template
```yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: My SAM Application
Resources:
SenderFunction:
Type: AWS::Serverless::Function
Properties:
Handler: functions.sender.app.lambda_handler
Runtime: python3.12
CodeUri: functions/sender/
ReceiverFunction:
Type: AWS::Serverless::Function
Properties:
Handler: functions.receiver.app.lambda_handler
Runtime: python3.12
CodeUri: functions/receiver/
Resulting Structure
.aws-sam/
├── build/
│ ├── SenderFunction/
│ │ ├── requirements.txt
│ │ ├── < project dependencies >
│ │ └── functions/
│ | └── sender/
│ | └── app.py
│ └── ReceiverFunction/
│ ├── requirements.txt
| ├── < project dependencies >
| └── functions/
│ └── receiver/
│ └── app.py
Basic Usage
uv export \
--locked \
--output-file requirements.txt
samwich-cli --requirements-path requirements.txt --template-file template.yaml
Options
--requirements-path: Path to your Python requirements.txt file. Defaults torequirements.txtin the current directory.--template-file: Path to your AWS SAM template file. Defaults totemplate.yamlin the current directory.--debug: Enable debug logging
How It Works
SAMWICH CLI performs the following actions:
- Analyzes your SAM template to identify Lambda functions and layers
- Copies your requirements.txt file to the appropriate locations
- Executes
sam buildto build your AWS resources - Updates the folder structure of your functions and layers to maintain consistency
Environment Variables
SAMWICH_WORKSPACE: Override the default workspace root (defaults to git repository root)SAMWICH_TEMP: Override the default temporary directory.
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development
- Clone the repository
- Install development dependencies with your package manager of choice
- Install pre-commit hooks:
pre-commit install
Code Quality
This project uses pre-commit hooks for code quality, including:
- Ruff for linting and formatting
- pycln for removing unused imports
- Various pre-commit hooks for file consistency
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file samwich_cli-0.1.0.tar.gz.
File metadata
- Download URL: samwich_cli-0.1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60ec07ab51358bcaf778e2e011f8b4168ea15b65c7d86ba6d66a72c7ca953e5d
|
|
| MD5 |
6cd3bf4d5aaa0aac1a3851960f038df6
|
|
| BLAKE2b-256 |
f99d4112545e88c34cc3a158474208ece545e0361f6862e025843df26d6310d4
|
File details
Details for the file samwich_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: samwich_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d771c0219fcb2bf753c6358117c8a3868d2af8be635ad324d5f7eed7d69b5e
|
|
| MD5 |
c41807da9958e8373fadf7d687a33de7
|
|
| BLAKE2b-256 |
c497ab41e6706ff28cddb1abebc01616413c5f45ba3f8c07c94f9345f1e90e0f
|