Reputation: 25
I'm trying to use CfnFunction
to crate lambda but everything works as expected except the uploading code
using
code_ = lambda_.CfnFunction.CodeProperty(
zip_file = "./function-code/db-snapshot/index.py")
or
zip_file = "./function-code/db-snapshot/index.zip")
after using this my lambda just creates only index.py
and the context of the file is the path
./function-code/db-snapshot/index.py
like this
Upvotes: 0
Views: 544
Reputation: 2400
the cfn methods are escape hatches for when the CDK Construct does not have the necessary properties that you are trying to access from CloudFormation yet.
Lambda, however, is pretty much a done deal in CDK - you should be using aws_cdk.aws_lambda.Function() for creating a cdk lambda resource (see link for docs)
Then from there you can use the aws_lambda.AssetCode()
methods to retrieve your code and zip it up for you
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"))
)
the above snippet assumes your have a file called index.py, and inside that file is a method defined as def handler(event, context):
that is the entry point for your lambda.
Upvotes: 1