Skip to main content

hatch-aws

PyPI - Version PyPI - Python Version Hatch project code style - black types - mypy imports - isort

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

  1. 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
    
  2. Specify common requirements for your project in pyproject.toml as dependencies.

    [project]
    dependencies = ["boto3"]
    
  3. 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 is GetAll_Accounts, use getall-accounts.

    [project.optional-dependencies]
    lambda1 = ["pyaml"]
    lambda2 = ["request", "pydantic"]
    
  4. 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"
    
  5. Set the CodeUri and Handler parameter pointing to your lambdas in SAM template. Only resources with Runtime: 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-exec str sam Path to sam executable. Env var: HATCH_SAM_EXEC.
sam-params array Additional sam build args.

License

Plugin hatch-aws is distributed under the terms of the MIT license.

Release files for hatch-aws 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hatch-aws 1.1.0
File Size Uploaded
hatch_aws-1.1.0.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hatch-aws 1.1.0
File Interpreter ABI Platform
hatch_aws-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / hatch_aws-1.1.0.tar.gz

Download URL hatch_aws-1.1.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
891d0b7ba7e1007045e6ac85f3fee0093a78742dd66481bebb127e52abdec77b
BLAKE2b-256 checksum
How to use checksums
fc73115eb29ab64a4cc77c40ff3e4f8838048d72f561d7e80640a6e23cf74c04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release files / hatch_aws-1.1.0-py3-none-any.whl

Download URL hatch_aws-1.1.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a0dc69267719bf239cc3da837403db7fa141e9cec0225354c934bd1223df5a7
BLAKE2b-256 checksum
How to use checksums
12b3c26f9b4076ed2de4aea0aaa5a61e438c5bc557ce1a11e8b4084a85e6d825
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page