@aws/cdk cfnfunction上传代码python结构
@aws/cdk cfnfunction upload code python structure
我正在尝试使用 CfnFunction
来创建 lambda,但除了使用
上传 code
之外,一切都按预期进行
code_ = lambda_.CfnFunction.CodeProperty(
zip_file = "./function-code/db-snapshot/index.py")
or
zip_file = "./function-code/db-snapshot/index.zip")
使用这个之后,我的 lambda 只创建了 index.py
并且文件的上下文是路径
./function-code/db-snapshot/index.py
像这样
当 CDK Construct 还没有您尝试从 CloudFormation 访问的必要属性时,cfn 方法是逃生通道。
Lambda,但是,在 CDK 中几乎是一个完成的交易 - 你应该使用 aws_cdk.aws_lambda.Function() 来创建一个 cdk lambda resource(参见 link 文档)
然后您可以使用 aws_lambda.AssetCode()
方法检索您的代码并为您压缩它
from aws_cdk import aws_lambda
aws_lambda.Function(self, "MyLambda",
runtime=Runtime.PYTHON_3_8,
handler="index.handler",
code=aws_lambda.AssetCode(os.path.join("path to your lambda directory", "index.py"))
)
上面的代码片段假定您有一个名为 index.py 的文件,并且该文件中有一个定义为 def handler(event, context):
的方法,它是您的 lambda 的入口点。
我正在尝试使用 CfnFunction
来创建 lambda,但除了使用
code
之外,一切都按预期进行
code_ = lambda_.CfnFunction.CodeProperty(
zip_file = "./function-code/db-snapshot/index.py")
or
zip_file = "./function-code/db-snapshot/index.zip")
使用这个之后,我的 lambda 只创建了 index.py
并且文件的上下文是路径
./function-code/db-snapshot/index.py
像这样
当 CDK Construct 还没有您尝试从 CloudFormation 访问的必要属性时,cfn 方法是逃生通道。
Lambda,但是,在 CDK 中几乎是一个完成的交易 - 你应该使用 aws_cdk.aws_lambda.Function() 来创建一个 cdk lambda resource(参见 link 文档)
然后您可以使用 aws_lambda.AssetCode()
方法检索您的代码并为您压缩它
from aws_cdk import aws_lambda
aws_lambda.Function(self, "MyLambda",
runtime=Runtime.PYTHON_3_8,
handler="index.handler",
code=aws_lambda.AssetCode(os.path.join("path to your lambda directory", "index.py"))
)
上面的代码片段假定您有一个名为 index.py 的文件,并且该文件中有一个定义为 def handler(event, context):
的方法,它是您的 lambda 的入口点。