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
Built Distribution
Hashes for aws_lambda-2.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a136fbca29f75d1a3925747e38174cdb79902d239925632739d141424ecd409 |
|
MD5 | b5a80551960a0679630c9cdc43eb6317 |
|
BLAKE2b-256 | 80fa7f1e103725217357389ded26cfd2f0a69468a7f615cb8e055cafc7a902be |