Skip to main content

Aws Lambda

A package used to manage lambda functions. With this package it is easy to create lambda deployment packages and create lambda resources with CloudFormation.

Description

An AWS Lambda management library which makes some of the painful parts less painful. E.g. This project makes it easy to create Lambda deployment packages and upload them to S3.

Prerequisites

In order to operate the package, you must first install it, using:

pip install aws-lambda

How to use

Making CloudFormation resources

With Troposphere
# Create a Troposphere template.
from troposphere import Template

# Create the initial template.
template: Template = Template()

# Create some of the resources for lambda function resource.
from troposphere.iam import Role
from troposphere.ec2 import Subnet
from troposphere.ec2 import SecurityGroup

lambda_role = Role(...)
lambda_subnets = [Subnet(...)]
lambda_security_groups = [SecurityGroup(...)]

# Import a lambda function resource class.
from aws_lambda.cloud_formation.lambda_troposphere import LambdaFunction

# Create a lambda function resource.
lambda_function = LambdaFunction(
    prefix='MyCustomPrefix',
    description='My custom description.',
    memory=128,
    timeout=300,
    handler='file.function',
    runtime='python3.8',
    role=lambda_role,
    env={},
    security_groups=lambda_security_groups,
    subnets=lambda_subnets
)

# Add lambda function to a Troposphere template.
lambda_function.add(template)
With AWS CDK
# Import AWS CDK core, iam, ec2, and lambda libraries.
from aws_cdk import core
from aws_cdk import aws_lambda
from aws_cdk import aws_iam
from aws_cdk import aws_ec2

# Create a CDK app.
app = core.App()

# Define a CDK stack class.
class MainStack(core.Stack):
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Import lambda function resource class.
        from aws_lambda.cloud_formation.lambda_aws_cdk import LambdaFunction

        lambda_vpc = aws_ec2.Vpc(...)
        lambda_role = aws_iam.Role(...)
        lambda_security_groups = [aws_ec2.SecurityGroup(...)]
        lambda_subnets = [aws_ec2.Subnet(...)]

        # Create lambda function.
        LambdaFunction(
            scope=self,
            prefix='MyCustomPrefix',
            description='My custom description.',
            memory=128,
            timeout=300,
            handler='file.function',
            runtime=aws_lambda.Runtime.PYTHON_3_8,
            role=lambda_role,
            env={},
            security_groups=lambda_security_groups,
            subnets=lambda_subnets,
            vpc=lambda_vpc
        )

# Create stack instance.
MainStack(app, "MainStack")

# Create a CloudFormation template.
app.synth()

Making Lambda deployment packages.

# Import deployment package manager class.
from aws_lambda.deployment.deployment_package import DeploymentPackage

# Suppose you have a project under a path:
SCR_PATH = '/home/user/projects/my_project'

# Suppose you have run 'aws configure' on your machine and have a default profile.
AWS_PROFILE = 'default'

# Create deployment manager instance.
deployment_package = DeploymentPackage(
    project_src_path=SCR_PATH,
    lambda_name='MyCoolLambda',
    s3_upload_bucket='MyCoolS3Bucket',
    s3_bucket_region='eu-west-1',
    aws_profile=AWS_PROFILE,
    environment='prod',
    refresh_lambda=True
)

# Initiate deployment.
deployment_package.deploy()

Release history

2.1.3

Use SubnetSelection.

2.1.1

Include md files.

2.1.1

Use time duration in CDK.

2.1.0

Add source code parameter.

2.0.1

Fix setup.py file.

2.0.0

Restructure. Add README and HISTORY files. Add docstrings.

Release files for aws-lambda 2.1.3

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

Source distribution (sdist)

Source distribution for aws-lambda 2.1.3
File Size Uploaded
aws_lambda-2.1.3.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-lambda 2.1.3
File Interpreter ABI Platform
aws_lambda-2.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 44.1 kB

Release files / aws_lambda-2.1.3.tar.gz

Download URL aws_lambda-2.1.3.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2e8d5cf46c6e9d30344295b56010dba2f243a43c893c585485c1ba00208be4ac
BLAKE2b-256 checksum
How to use checksums
bc8c1a2f1362313fe8f941654c6e3c396927e6f264221be8e4b033cac6042bdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.15+

Release files / aws_lambda-2.1.3-py3-none-any.whl

Download URL aws_lambda-2.1.3-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a136fbca29f75d1a3925747e38174cdb79902d239925632739d141424ecd409
BLAKE2b-256 checksum
How to use checksums
80fa7f1e103725217357389ded26cfd2f0a69468a7f615cb8e055cafc7a902be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.15+

Release history Release notifications | RSS feed

This release

2.1.3 This release

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.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