Skip to main content

Hatch plugin for building AWS Lambda functions with SAM

Project description

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.


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 enable it, include following configuration in you config file:

  • pyproject.toml

    [tool.hatch.build.targets.aws]
    
  • hatch.toml

    [build.targets.aws]
    

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 module (folder) name.

    [project.optional-dependencies]
    lambda1 = ["pyaml"]
    lambda2 = ["requrest", "pydantic"]
    
  4. Specify additional folders and files you want to copy to the build folder.

    [tool.hatch.build.targets.aws]
    include = ["src/my_app/common"]
    
  5. Set the CodeUri and Handler parameter pointing to your lambdas in SAM template.

    Resources:
     Lambda1:
       Type: AWS::Serverless::Function
       Properties:
         FunctionName: lambda1-function
         CodeUri: src
         Handler: my_app.lambdas.lambda1.main.app
         ...
    
     Lambda2:
       Type: AWS::Serverless::Function
       Properties:
         FunctionName: lambda2-function
         CodeUri: src
         Handler: my_app.lambdas.lambda2.main.app
         ...
    
  6. Run hatch build command.

    โฏ hatch build
    [aws]
    Building lambda functions ...
    Lambda1 ... success
    Lambda2 ... success
    Build successfull ๐Ÿš€
    /path/to/projects/.aws-sam/build
    

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 The filename of a SAM template.
use-sam bool false Use only SAM for build. Do not run custom copy actions.
sam-params array Pass additional options to a SAM build command

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

hatch_aws-0.2.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

hatch_aws-0.2.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file hatch_aws-0.2.0.tar.gz.

File metadata

  • Download URL: hatch_aws-0.2.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for hatch_aws-0.2.0.tar.gz
Algorithm Hash digest
SHA256 06a2d640ee03fb33b7ba570d7bc288d83a4411c81998778f6b4c8f1ba826acd5
MD5 a59a0cf4de711f569b257d2faf3d4324
BLAKE2b-256 587e9cfb376ef3d05051cb804b53bc733299556457bcee83831a8ae9ef5799d4

See more details on using hashes here.

File details

Details for the file hatch_aws-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: hatch_aws-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for hatch_aws-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99e56296e2efa6b1f4267ce4be91006e68fa3b4bee366e699c1efd918edf776f
MD5 8a11ef26e9697fede8c269b406d84282
BLAKE2b-256 b98fc02a14bceed0c4fafeb0c84da6c42eb0333ba24dfc310c1a759718dfc365

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page