Skip to main content

AWS CDK based lambda layer including useful utilities.

Project description

B.CfnLambdaLayer

Pipeline

Easy lambda dependency management is here!
This is an AWS CDK resource that acts as a LayerVersion resource but with more convenient approach to specify and bundle dependencies.

Description

AWS CDK already makes it incredibly simple to package code for lambda functions and layers by exposing Code resource and methods like Code.from_asset(). However, it is very difficult to add additional dependencies to your layer code e.g. jose, requests, newer boto3 library, etc. This custom layer resource makes packaging code with dependencies extremely simple like 2 + 2! You simply specify a dictionary of dependencies to include and this resource will do the rest.

You should note that this resource uses docker to bundle code and dependencies.

Remarks

Biomapas aims to modernise life-science industry by sharing its IT knowledge with other companies and the community. This is an open source library intended to be used by anyone. Improvements and pull requests are welcome.

Related technology

  • Python3
  • Docker
  • AWS CDK
  • AWS CloudFormation
  • AWS Lambda
  • AWS Lambda Layer
  • AWS Lambda Layer bundling with Docker

Assumptions

This project assumes you know what Lambda functions are and how code is being shared between them (Lambda layers).

  • Excellent knowledge in IaaC (Infrastructure as a Code) principles.
  • Excellent knowledge in Lambda functions and Lambda layers.
  • Good experience in AWS CDK and AWS CloudFormation.
  • Good Python skills and basis of OOP.

Useful sources

Install

Before installing this library, ensure you have these tools setup:

  • Python / Pip
  • AWS CDK
  • Docker

To install this project from source run:

pip install .

Or you can install it from a PyPi repository:

pip install b-cfn-lambda-layer

Usage & Examples

The most convenient feature of this resource is easy dependency management. When creating a new layer you simply supply a dictionary of dependencies, and they will be installed and packaged to you layer at a deployment level:

from b_cfn_lambda_layer.package_version import PackageVersion

dependencies = {
    'python-jose': PackageVersion.from_string_version('3.3.0'),
    'boto3': PackageVersion.from_string_version('1.16.35'),
    'botocore': PackageVersion.from_string_version('1.19.35')
}

This is a full example where we create a lambda layer and use it in lambda function.

from aws_cdk.aws_lambda import Function, Code, Runtime
from aws_cdk.core import Stack

from b_cfn_lambda_layer.lambda_layer import LambdaLayer
from b_cfn_lambda_layer.package_version import PackageVersion

# Create layer with custom dependencies.
layer = LambdaLayer(
    scope=Stack(...),
    name='TestLayer',
    # You can conveniently specify path to source code to include.
    source_path='/path/to/your/layer/source/code',
    code_runtimes=[Runtime.PYTHON_3_6, Runtime.PYTHON_3_7, Runtime.PYTHON_3_8],
    # You can conveniently specify dependencies to include.
    dependencies={
        'python-jose': PackageVersion.from_string_version('3.3.0'),
        'boto3': PackageVersion.from_string_version('1.16.35'),
        'botocore': PackageVersion.from_string_version('1.19.35')
    }
)

# Create a function with a layer.
Function(
    scope=Stack(...),
    id='MyFunction',
    code=Code.from_asset('/path/to/lambda/function/code'),
    handler='index.handler',
    runtime=Runtime.PYTHON_3_6,
    # Specify layers.
    layers=[layer]
)

Testing

This package has integration tests based on pytest. To run tests simply run:

pytest b_cfn_lambda_layer_test/integration/tests

Contribution

Found a bug? Want to add or suggest a new feature? Contributions of any kind are gladly welcome. You may contact us directly, create a pull-request or an issue in github platform. Lets modernize the world together.

Release history

2.0.3

  • Add missing Dockerfile in MANIFEST.

2.0.2

  • Fix type hints.

2.0.1

  • Actually, make it compatible with previous versions (at least from the layer_name -> name perspective).

2.0.0

  • Complete code refactor.
  • Change cmd line based bundling to Dockerfile based bundling.
  • Deprecated requirements.txt functionality. The library will no longer install dependencies if a requirements.txt file is found within source code.

1.1.3

  • Retain dist-utils when bundling layer.

1.1.1

  • Small bug fix to include parent directory only for source code.

1.1.0

  • Add ability to include parent directory when bundling.

1.0.0

  • Improve documentation.
  • This is a fully working production-ready library.

0.0.2

  • Add documentation.

0.0.1

  • Initial build.

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

b_cfn_lambda_layer-2.0.3.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b_cfn_lambda_layer-2.0.3-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file b_cfn_lambda_layer-2.0.3.tar.gz.

File metadata

  • Download URL: b_cfn_lambda_layer-2.0.3.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.12

File hashes

Hashes for b_cfn_lambda_layer-2.0.3.tar.gz
Algorithm Hash digest
SHA256 504d36d87b5208a42f959604a85b4dbada62ebbb474c737d557acfb2518b295c
MD5 4bf1eb45557f7b6d5d3704c4bc81ea4b
BLAKE2b-256 ef052133a7f07a2a393f1ee87b59587cbe586d1d8478d957c8bc5cd9d5090afc

See more details on using hashes here.

File details

Details for the file b_cfn_lambda_layer-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for b_cfn_lambda_layer-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4a6272df071c89f39bf26af4a8d39e9dcd913b0b62c379376c128a3388db7989
MD5 30cb33b62db2e433d4437378d588e035
BLAKE2b-256 dbd889c7b7dbc35878e79b91f89bd4923c25b98eea346588b080a47794835fba

See more details on using hashes here.

Supported by

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