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
from aws_cdk import aws_apigateway as apigateway
app = cdk.App()
stack = cdk.Stack(app, 'HelloLambdecor')
@aws_lambda(stack)
def ping(url):
http = urllib3.PoolManager()
r = http.request('GET', url)
return r.status
api = apigateway.LambdaRestApi(...)
status = ping(api.url)
cdk.CfnOutput(stack, 'Status', value=status)
app.synth()
Runtime
The Custom Resource is created with the Python3.6 Lambda Runtime
Imports
The following modules are pre-imported into the lambda environment:
json
urllib3
To use any other module, you would need to do an inline import.
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
File details
Details for the file aws_cdk_lambdecor-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: aws_cdk_lambdecor-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e0d1b6b2b639043f3d3b93bc14ee760fb65be4beff68083144a5f433dc6c5e7 |
|
MD5 | 45cafb9431630aeef6a8ae3d1800fcf8 |
|
BLAKE2b-256 | 83743cc359c075805f955bc6aa481aef3cfbbf812ea775ecd1311e281e2c5457 |