andmarek
andmarek

Reputation: 31

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).

Upvotes: 3

Views: 1102

Answers (1)

Michael
Michael

Reputation: 1522

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.

Upvotes: 2

Related Questions