https://github.com/iliapolo/aws-cdk-lambdecor
Native python functions as AWS CDK Custom Resources
https://github.com/iliapolo/aws-cdk-lambdecor
aws-cdk aws-lambda-python python
Last synced: 4 months ago
JSON representation
Native python functions as AWS CDK Custom Resources
- Host: GitHub
- URL: https://github.com/iliapolo/aws-cdk-lambdecor
- Owner: iliapolo
- License: apache-2.0
- Created: 2020-08-27T19:36:31.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-30T09:58:10.000Z (about 5 years ago)
- Last Synced: 2025-02-04T09:23:21.794Z (9 months ago)
- Topics: aws-cdk, aws-lambda-python, python
- Language: Python
- Homepage:
- Size: 45.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pypi.org/project/aws-cdk-lambdecor/)
[](https://pypi.org/project/aws-cdk-lambdecor/)
[](https://github.com/iliapolo/aws-cdk-lambdecor)
# aws-cdk-lambdecor
Transform native python function into [AWS CDK Custom Resources](https://docs.aws.amazon.com/cdk/api/latest/docs/custom-resources-readme.html).
```python
from aws_cdk_lambdecor import aws_lambda
from aws_cdk import core as cdkapp = 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:
```python
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 apigatewayapp = cdk.App()
stack = cdk.Stack(app, 'HelloLambdecor')@aws_lambda(stack)
def ping(url):
http = urllib3.PoolManager()
r = http.request('GET', url)
return r.statusapi = 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](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)
### 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.e `result=$(aws-cdk-lamdecor invoke func.py)`)