Hatch plugin for building AWS Lambda functions with SAM
Project description
hatch-aws
AWS builder plugin for Hatch ๐ฅ๐. Hatch is modern, extensible Python project manager.
Checkout my other plugin hatch-aws-publisher.
Table of Contents
Global dependency
Add hatch-aws
within the build-system.requires
field in your pyproject.toml
file.
[build-system]
requires = ["hatchling", "hatch-aws"]
build-backend = "hatchling.build"
Builder
The builder plugin name is called aws
.
To start build process, run hatch build -t aws
:
โฏ hatch build -t aws
[aws]
Building lambda functions ...
MyAwsLambdaFunc ... success
Build successfull ๐
/path/to/build/.aws-sam/build
How to use it
-
Put your module and lambdas inside of
src
folder.. โโโ pyproject.toml โโโ src โ โโโ my_app โ โโโ __init__.py โ โโโ common โ โ โโโ __init__.py โ โ โโโ config.py โ โ โโโ models.py โ โโโ lambdas โ โโโ lambda1 โ โ โโโ __init__.py โ โ โโโ main.py โ โโโ lambda2 โ โโโ __init__.py โ โโโ main.py โโโ template.yml
-
Specify common requirements for your project in
pyproject.toml
as dependencies.[project] dependencies = ["boto3"]
-
Specify requirements for your lambda functions in
pyproject.toml
as optional dependencies. Use resource name from SAM template, but you have to adapt it to be compliant with PEP standard (transform to lower case and replace_
with-
). For example, if you function name in SAM template isGetAll_Accounts
, usegetall-accounts
.[project.optional-dependencies] lambda1 = ["pyaml"] lambda2 = ["request", "pydantic"]
-
Specify additional paths(source/destination) you want to copy to the build folder. Destination is relative to a build directory (
.aws-sam/build
by default). You can use glob*
to copy common to all lambda functions.[tool.hatch.build.force-include] "src/batman/common" = "*/batman/common" # copy to all lambda functions ".editorconfig" = ".editorconfig.txt" "CHANGELOG.md" = "../CH.txt" "images/" = "*/images"
-
Set the
CodeUri
andHandler
parameter pointing to your lambdas in SAM template. Only resources withRuntime: python{version}
are supported. The rest is ignored.Resources: Lambda1: Type: AWS::Serverless::Function Properties: Runtime: python3.9 FunctionName: lambda1-function CodeUri: src Handler: my_app.lambdas.lambda1.main.app ... Lambda2: Type: AWS::Serverless::Function Properties: Runtime: python3.9 FunctionName: lambda2-function CodeUri: src Handler: my_app.lambdas.lambda2.main.app ...
Options
Following table contains available customization of builder behavior. You can find example of pyproject.toml
in tests/assets/pyproject.toml.
Option | Type | Default | Description |
---|---|---|---|
template |
str |
template.yml |
SAM template filename. |
use-sam |
bool |
false |
Use only sam build command without any custom actions. |
sam-params |
array |
Additional sam build args. |
License
Plugin hatch-aws
is distributed under the terms of the MIT license.
Project details
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
File details
Details for the file hatch_aws-1.0.0.tar.gz
.
File metadata
- Download URL: hatch_aws-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a710a0348a2814803ef630185323c90e827472d8a8f6ba6495abf9125ef09af1 |
|
MD5 | c3069e0ebf37e740f62a6d15a701a515 |
|
BLAKE2b-256 | e7f56bd5b0fc1d52d3bae7841273812f11b02e8bf5eda411514ee6a3b687c8cc |
File details
Details for the file hatch_aws-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: hatch_aws-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92fbc87446f7d2223031a5574515b6f3ce4f3f746d9d56dc5f2319b60d4a283a |
|
MD5 | ac67c1aef7dc88d35de564b9dbd58266 |
|
BLAKE2b-256 | 70b869781fab6512ae772914cc08a7da157904d1d17057fc323b93316a9d6964 |