Skip to main content

CDK Ast Lambda Rest Api - CDK Package

Project description

CDK Ast Lambda Rest API - CDK Packge (CALRA)

A library for AWS API Gateway/Lambda Proxy Integration

CALRA allows simplified resource creation for AWS Lambda functions and Rest API resources by using decorators and setting a builder with default, common or custom values for IAM Roles, Runtimes, Timeouts, Layers, Environment values, etc. This project relies abstract syntactic trees (ast) to analyze the code of your lambda functions and generate infraestructure accordingly.

Installation

calra_cdk is available from PyPI as calra-cdk:

pip install calra-cdk

Installation of calra-lambda is also required as a dependency for your lambda functions, since it provides the definition of decorators used within this module. You can as well rely on the calra-example repository to get started.

Example

    import calra_cdk
    or
    from calra_cdk import ResourceBuilder

Builder instance

You may define a builder using calra_cdk's constructor ResourceBuilder. This method returns an instance of the class that will be used to configure and create your Lambda Functions. By default, no parameters are required to instantiate the object, but custom options may be passed in advanced use cases.

    from calra_cdk import ResourceBuilder

    builder = ResourceBuilder()

Builder Configuration

If opted to, you can set default values for IAM Roles, Memory Size, Timeout, Runtime and VPC.

On the same note, support for common configuration that all the Lambda Functions will receive, such as Security Groups, Environment variables and Layers, is provided.

Lastly you can setup custom environments, layers, security groups, vpcs a Lambda Function will receive ONLY if they have the decorators defined.

    from calra_cdk import ResourceBuilder
    from aws_cdk import Duration

    builder = ResourceBuilder()
    builder.set_default_timeout(Duration.seconds(30))
    builder.add_common_environment("DATABASE_URI", "something-db-related")
    builder.add_custom_environment("URL-PREFIX", "calra-cdk-") #Lambda Function should have decorator @environment("URL-PREFIX")

Building

Assuming you have already instantiated a Builder, configured it and ready to deploy your stack, then simply define the directory of your Lambda Functions and build!

Note: For a Lambda Function to be recognised and built, it has to have a decorator specifying the HTTP method it responds to. Again, the calra-example repository will provide a firm example of a builder setting and proper lambda annotation using decorators defined in the calra-lambda package.

[...] # Imports

class CalraExampleStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        [...]  # Instantiating builder, defining options and layers...

        lambda_path = 'lambdas'

        restapi = apigateway.RestApi(
            self, 'calra-RestApi',
            rest_api_name= 'calra-restApi')
        root_resource = restapi.root

        builder.build(self, root_resource, lambda_path, print_tree=True)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

calra_cdk-0.3.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file calra_cdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: calra_cdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for calra_cdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b17a5e41adf31ece96aff2e5caa61446c7b0d92aa1683d57d6b3d25c86565f6e
MD5 71e7c063a716880e439c71800494621f
BLAKE2b-256 c862bd655fe55cbf84d79dd59dee3f633d3817e0e94c0d1759d10c8b593ff4f8

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