Define AWS CDK Lambda using native python functions
Project description
aws-cdk-lambdecor
Transform native python function into AWS CDK Custom Resources.
from aws_cdk_lambdecor import aws_lambda
from aws_cdk import core as cdk
app = cdk.App()
stack = cdk.Stack(app, 'HelloLambdecor')
@aws_lambda(stack)
def greet():
return 'hello'
# invoke the function just like a regular function
greeting = greet()
# return value is a token that can be used later on
cdk.CfnOutput(stack, 'Greeting', value=greeting)
app.synth()
You can also use tokens:
from aws_cdk_lambdecor import aws_lambda
from aws_cdk import core as cdk
from aws_cdk import s3
app = cdk.App()
stack = cdk.Stack(app, 'HelloLambdecor')
@aws_lambda(stack)
def download_index(bucket_name):
return download(f's3://{bucket_name}/index.html')
bucket = s3.Bucket.from_bucket_name(stack, 'Website', 'www.mysite.com')
index = download_index(bucket.bucket_name)
cdk.CfnOutput(stack, 'Index', value=index)
app.synth()
Runtime
The Custom Resource is created with the Python3.6 Lambda Runtime
Imports
Your function code should do an inline import of the python module you want to use. For example, to use the urllib3
module, you would write:
@aws_lambda(stack)
def download():
import urllib3
# do something...
The
json
library is pre-imported, so you don't have to do this to usejson
.
Install
pip install aws-cdk-lambdecor
Possible Future Work
- Support customizing all properties of the CDK Lambda Function (i.e runtime, memory, environment...)
- Pre-import additional common libraries.
- Implicit CDK scope creation to support CDK applications consisting of just these lambda functions.
- Implicit creation of Stack output.
- Command line invocation of function that runs
cdk deploy
and parses the stack output. (i.eresult=$(aws-cdk-lamdecor invoke func.py)
)
Project details
Release history Release notifications | RSS feed
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
Close
Hashes for aws_cdk_lambdecor-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 203367020682c9eb128858a22dff051d33dc43be0fd1ae4354c61547dcf47c84 |
|
MD5 | a7669b0bfd8e8e7f69e24c63f763d81d |
|
BLAKE2b-256 | b124a355c19c8725009b087a0e7c4c28ef028798e3fc5053a5a2e2c949ca56d2 |