Skip to main content

Package which helps to do various actions associated with AWS Lambda functions.

Project description

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.

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

aws_lambda-2.1.3.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

aws_lambda-2.1.3-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file aws_lambda-2.1.3.tar.gz.

File metadata

  • Download URL: aws_lambda-2.1.3.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using 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+

File hashes

Hashes for aws_lambda-2.1.3.tar.gz
Algorithm Hash digest
SHA256 2e8d5cf46c6e9d30344295b56010dba2f243a43c893c585485c1ba00208be4ac
MD5 94010f034953553f32b9da8adaaccf5c
BLAKE2b-256 bc8c1a2f1362313fe8f941654c6e3c396927e6f264221be8e4b033cac6042bdc

See more details on using hashes here.

File details

Details for the file aws_lambda-2.1.3-py3-none-any.whl.

File metadata

  • Download URL: aws_lambda-2.1.3-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using 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+

File hashes

Hashes for aws_lambda-2.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a136fbca29f75d1a3925747e38174cdb79902d239925632739d141424ecd409
MD5 b5a80551960a0679630c9cdc43eb6317
BLAKE2b-256 80fa7f1e103725217357389ded26cfd2f0a69468a7f615cb8e055cafc7a902be

See more details on using hashes here.

Supported by

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