项目作者: iliapolo

项目描述 :
Native python functions as AWS CDK Custom Resources
高级语言: Python
项目地址: git://github.com/iliapolo/aws-cdk-lambdecor.git
创建时间: 2020-08-27T19:36:31Z
项目社区:https://github.com/iliapolo/aws-cdk-lambdecor

开源协议:Apache License 2.0

下载


PyPI Version
Is Wheel
PyCI release
Build Status

aws-cdk-lambdecor

Transform native python function into AWS CDK Custom Resources.

  1. from aws_cdk_lambdecor import aws_lambda
  2. from aws_cdk import core as cdk
  3. app = cdk.App()
  4. stack = cdk.Stack(app, 'HelloLambdecor')
  5. @aws_lambda(stack)
  6. def greet():
  7. return 'hello'
  8. # invoke the function just like a regular function
  9. greeting = greet()
  10. # return value is a token that can be used later on
  11. cdk.CfnOutput(stack, 'Greeting', value=greeting)
  12. app.synth()

You can also use tokens:

  1. from aws_cdk_lambdecor import aws_lambda
  2. from aws_cdk import core as cdk
  3. from aws_cdk import s3
  4. from aws_cdk import aws_apigateway as apigateway
  5. app = cdk.App()
  6. stack = cdk.Stack(app, 'HelloLambdecor')
  7. @aws_lambda(stack)
  8. def ping(url):
  9. http = urllib3.PoolManager()
  10. r = http.request('GET', url)
  11. return r.status
  12. api = apigateway.LambdaRestApi(...)
  13. status = ping(api.url)
  14. cdk.CfnOutput(stack, 'Status', value=status)
  15. 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.e result=$(aws-cdk-lamdecor invoke func.py))