Skip to main content

AWS CDK based lambda layer including useful utilities.

Project description

B.LambdaLayerCommon

Pipeline

A lambda layer resource that contains various useful methods.

Description

This is a simple lambda layer, that contains various useful methods that will make infrastructure development much easier. It also allows you to easily manage (add) additional external dependencies. Note, docker is used to build this code.

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 Lambda
  • AWS Lambda Layer

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-lambda_layer_common

Usage & Examples

Main modules:

  • api_gateway
    Contains various functionalities related to API Gateway service and integrations.

  • cache
    Contains caching mechanisms for lambda functions.

  • events
    Contains functionality that supports event-driven architectures.

  • exceptions
    Contains advanced exception handling and propagation between lambda function chains.

  • ssm
    Contains SSM parameter store handling logic.

  • util
    Contains random fun stuff ;)

  • ws_api_gateway
    Contains various functionalities related to API Gateway websocket service and integrations.

Using this layer is extremely simple. Create it like this:

from aws_cdk.core import Stack, DockerImage
from b_lambda_layer_common.layer import Layer
from b_cfn_lambda_layer.package_version import PackageVersion

Layer(
    scope=Stack(),
    name='MyLayer',
    additional_pip_install_args='--pre',
    dependencies={
        'boto3': PackageVersion.from_string('1.16.35'),
    },
    docker_image=DockerImage.from_registry('python:3.9')
)

Or without any optional arguments:

from aws_cdk.core import Stack
from b_lambda_layer_common.layer import Layer

Layer(
    scope=Stack(),
    name='MyLayer',
)

Once you have deployed a lambda function with this layer, you can start using previously mentioned modules. For example, lets use an API-Gateway-formatted response:

from b_lambda_layer_common.api_gateway.response import Response

def handler(*args, **kwargs):
    return Response.json(
      http_status=200,
      body={
        'key': 'value'
      }
    )

Testing

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

pytest --cov=b_lambda_layer_common b_lambda_layer_common_test/unit --cov-fail-under=80

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

pytest b_lambda_layer_common_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.3.0

  • Add Fernet encryption PynamoDB attribute.

2.2.1

  • Fix KmsAttribute by introducing base64 encode/decode.

2.2.0

  • Add field validator in util directory. Simple string validation.
  • Add KMS attribute for PynamoDB.

2.1.2

  • Add a list bytes batching utility.

2.0.6

  • Handle errors when raising ValueError in SfnCall class.

2.0.4

  • Simple return JSON of an output if SfnCall raised ValueError.

2.0.1

  • Include .txt files.

2.0.0

  • Complete refactor.
  • Fix ugly if/else imports.
  • Run unit tests inside lambda functions.
  • Use b_cfn_lambda_layer dependency.
  • Write more unit and integration tests.
  • Add README documentation.

1.20.0

  • Add validation when bundling with Docker.

1.19.0

  • General testing improvements.
  • Add Layer V2 integration tests.

1.18.0

  • Add V2 Layer class to enable installation of dependencies.

1.16.0

  • Add response method to return any type.
  • Add text/html and text/plain headers.
  • Add missing fields parameter support to NeighbourEndpoint class.

1.15.1

  • Improve function return value handling for InMemoryDataCache class.

1.15.0

  • Add in-memory data caching functionality.

1.14.0

  • Add fields parameter support to HttpEndpoint class.

1.11.1

  • Update DoNotUpdate class to be usable as a type.

1.11.0

  • Add WebSocket Api Gateway message class to form consistent messages.

1.10.2

  • Allow for changing HttpEndpoint behavior.

1.10.1

  • Add ability to specify if to fail to errors.
  • Try to read from env event bus name.

1.10.0

  • Add factory to emit EventBridge events.

1.9.5

  • Make the code a little more robust and less error prone.

1.9.4

  • Assets input may contain garbage files too, hence, apply cleanup commands directly on asset outputs folder.

1.9.3

  • Add builds badge.

1.9.2

  • Remove leftover code.
  • Update requirements.

1.9.1

  • Delete unnecessary files which result in different asset hash.
  • Calculate hash when bundling.

1.9.0

  • Add CSV headers.

1.8.3

  • Ensure everything works with a robust integration test.

1.8.2

  • Improve Boto3Version class.

1.8.1

  • Fix bug when boto3 version is specified project files are not copied.

1.8.0

  • Change asset bundling to asset docker bundling if additional dependencies are specified.
  • Add ability to install boto3 library.
  • Add more unit tests.
  • Add integration tests to deploy and test the Layer in AWS.

1.7.0

  • Simplify SSM parameters functionality.
  • Add robust SSM parameter tests.

1.6.2

  • Do not serialize returned ssm parameters.

1.6.1

  • Add more logging for better visibility.

1.6.0

  • SSM should_refresh function should be public.

1.5.1

  • Add logging on ssm error decorator.

1.5.0

  • Force using error_class to error_classes.

1.4.0

  • Add functionality to fetch and cache SSM parameters.
  • Add OS type parameters.

1.3.0

  • Add media Response and wav/mpeg headers.

1.2.0

  • Add DoNotUpdate class, useful when checking what parameters to update and what not.

1.1.3

  • Implement retrying logic to HttpCall.

1.1.2

  • Make sure test coverage is at least 80%.
  • Add CI/CD pipeline.
  • Add more encodings to decode responses.

1.1.1

  • Add urllib3 dependency.

1.1.0

  • Add DynamoDBEncoder that subclasses DecimalEncoder and additionally encodes sets as lists.

1.0.3

  • Modify call_to_json function by checking whether the response contains body.

1.0.2

  • Add exception logging for failed imports.

1.0.1

  • Expose http_endpoint on NeigbourEndpoint class.

1.0.0

  • Release version with major braking changes.
  • Consistent naming for imports.
  • Unit tests to cover all functions and classes.
  • Add neighbour endpoint.
  • General code improvements and cleanup.

0.0.16

  • Fix logging imports.
  • Add logging of exception tracebacks to exception_middleware.
  • Add logging about HTTP requests.
  • Set request scheme for parent API Gateway urls depending on current protocol.

0.0.15

  • Add a CognitoAccessToken for parsing access token information provided by the API Gateway using Cognito authorizer.

0.0.14

  • Add a LoggingManager for setting up logging configuration

0.0.13

  • Add custom JSON encoder with support for decimal.Decimal encoding

0.0.12

  • Implement API Gateway body parsing.

0.0.11

  • Fix imports.

0.0.10

  • Implement exceptions.

0.0.9

  • Fix api gateway url.

0.0.8

  • Add xml to dict converter utility. No dependencies.

0.0.7

  • Fix imports.

0.0.6

  • Add ability to check whether singleton was initialized.

0.0.5

  • Remove description.

0.0.4

  • Do not create an extra stack.

0.0.3

  • Add safe initialization.

0.0.2

  • Add Layer class and Singleton.

0.0.1

  • Initial build.

Project details


Release history Release notifications | RSS feed

This version

2.3.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b_lambda_layer_common-2.3.0.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

b_lambda_layer_common-2.3.0-py3-none-any.whl (73.8 kB view details)

Uploaded Python 3

File details

Details for the file b_lambda_layer_common-2.3.0.tar.gz.

File metadata

  • Download URL: b_lambda_layer_common-2.3.0.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for b_lambda_layer_common-2.3.0.tar.gz
Algorithm Hash digest
SHA256 716c9363b7e1489e9d2d1e87466a734a8887b1b95104dddd6425a7544b9f18bf
MD5 de23b59048dceb5c437cea18c32698dd
BLAKE2b-256 a081731e288c645e739c98f4134e3dc7359d754095da6cc97504a3e3b8d506b4

See more details on using hashes here.

File details

Details for the file b_lambda_layer_common-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: b_lambda_layer_common-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 73.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for b_lambda_layer_common-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 503233a1c9abff33f331dc90440286cb39fa5b783c8c7f5a3130f401e0784bc2
MD5 ea45189af048961e1aa47c888f30cb2f
BLAKE2b-256 dc1f87de35c2b9a96b9b3ec1560f67d041b98c218ffa44d3e885a5f08e620a8f

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