Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I satisfy the AWS CDK Lambda's CfnFunction "code" parameter in Python?

I'm attempting to translate a YAML CloudFormation template into AWS's CDK using Python. I am currently stuck on instantiating a lambda CfnFunction. It appears that I am not satisfying the required "code" parameter.

My current code looks like:

firehose_trans_lambda = _lambda.CfnFunction(self, "FirehoseTransformLambda",
        description="foo", 
        code=, 
        handler="lambda_function.handler", 
        role="LambdaTransformRole.Arn",
        runtime="python3.8",
    )

According to the CDK documentation, the "code" field should be of type (Union[Forwardref, IResolvable]). I have no idea what this means, and the documentation isn't very helpful. Does anybody have any insight as to what I could put in there to satisfy the requirements? I was thinking of trying either a reference to some lambda or a piece of inline code, but am not sure how to go about doing that (I have tried various things, but my Python skills aren't the strongest).

like image 360
andmarek Avatar asked Jul 29 '26 04:07

andmarek


1 Answers

The code paramter expects an instance of CfnFunction.CodeProperty. Its __init__ accepts the following parameters (all optional and of type str)

  • s3_bucket
  • s3_key
  • s3_object_version
  • zip_file

You can pass the same values to CfnFunction.CodeProperty() that you've used in your CloudFormation template. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html

Afaik CfnFunction.CodeProperty isn't mentioned in the AWS CDK Python Reference. The general CDK documentation mentions it, but only as an interface.

like image 76
Michael Avatar answered Jul 30 '26 17:07

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!