Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDK adds random parameters

So I have this function I'm trying to declare and it works and deploys just dandy unless you uncomment the logRetention setting. If logRetention is specified the cdk deploy operation adds additional parameters to the stack. And, of course, this behavior is completely unexplained in the documentation.

https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-readme.html#log-group

SingletonFunction.Builder.create(this, "native-lambda-s3-fun")
                        .functionName(funcName)
                        .description("")
                        // .logRetention(RetentionDays.ONE_DAY)
                        .handler("app")
                        .timeout(Duration.seconds(300))
                        .runtime(Runtime.GO_1_X)
                        .uuid(UUID.randomUUID().toString())
                        .environment(new HashMap<String, String>(){{
                            put("FILE_KEY", "/file/key");
                            put("S3_BUCKET", junk.getBucketName());
                        }})
                        .code(Code.fromBucket(uploads, functionUploadKey(
                                "formation-examples",
                                "native-lambda-s3",
                                lambdaVersion.getValueAsString()
                        )))
                        .build();
"Parameters": {
    "lambdaVersion": {
      "Type": "String"
    },
    "AssetParametersceefd938ac7ea929077f2e2f4cf09b5034ebdd14799216b1281f4b28427da40aS3BucketB030C8A8": {
      "Type": "String",
      "Description": "S3 bucket for asset \"ceefd938ac7ea929077f2e2f4cf09b5034ebdd14799216b1281f4b28427da40a\""
    },
    "AssetParametersceefd938ac7ea929077f2e2f4cf09b5034ebdd14799216b1281f4b28427da40aS3VersionKey6A2AABD7": {
      "Type": "String",
      "Description": "S3 key for asset version \"ceefd938ac7ea929077f2e2f4cf09b5034ebdd14799216b1281f4b28427da40a\""
    },
    "AssetParametersceefd938ac7ea929077f2e2f4cf09b5034ebdd14799216b1281f4b28427da40aArtifactHashEDC522F0": {
      "Type": "String",
      "Description": "Artifact hash for asset \"ceefd938ac7ea929077f2e2f4cf09b5034ebdd14799216b1281f4b28427da40a\""
    }
  },

like image 455
Keynan Avatar asked Mar 25 '26 14:03

Keynan


2 Answers

It's a bug. They're Working On It™. So, rejoice - we can probably expect a fix sometime within the next decade.


I haven't tried it yet, but I'm guessing the workaround is to manipulate the low-level CfnLogGroup construct, since it has the authoritative retentionInDays property. The relevant high-level Log Group construct can probably be obtained from the Function via its logGroup property. Failing that, the LogGroup can be created from scratch (which will probably be a headache all on its own).

like image 185
Andrey Avatar answered Mar 27 '26 06:03

Andrey


I also encountered the problem described above. From what I can tell, we are unable to specify a log group name and thus the log group name is predictable.

My solution was to simply create a LogGroup with the same name as my Lambda function with the /aws/lambda/ prefix.

Example:

var function = new Function(
    this,
    "Thing",
    new FunctionProps
    {
        FunctionName = $"{Stack.Of(this).StackName}-Thing",
        // ...
    });

_ = new LogGroup(
    this,
    "ThingLogGroup",
    new LogGroupProps
    {
        LogGroupName = $"/aws/lambda/{function.FunctionName}",
        Retention = RetentionDays.ONE_MONTH,
    });

This does not create unnecessary "AssetParameters..." CF template parameters like the inline option does.

Note: I'm using CDK version 1.111.0 and 1.86.0 with C#

like image 32
Robert Hodgen Avatar answered Mar 27 '26 05:03

Robert Hodgen



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!