Skip to content

cloud-assembly-schema: MetadataEntryData type missing boolean | number  #4742

@matusfaro

Description

@matusfaro

Describe the bug

Bumping to latest dependencies and going from cloud schema 36.0.0 to 38.0.1, I get the following error:

[ERROR] Failed to execute goal io.dataspray:aws-cdk-maven-plugin:2.3.1-SNAPSHOT:synth (run-cdk-synth) on project dataspray-package:
   Unable to initialize interface proxy software.amazon.awscdk.cloud_assembly_schema.AssemblyManifest.Jsii$Proxy: InvocationTargetException:
   Unable to initialize interface proxy software.amazon.awscdk.cloud_assembly_schema.ArtifactManifest.Jsii$Proxy:
   Unable to initialize interface proxy software.amazon.awscdk.cloud_assembly_schema.MetadataEntry.Jsii$Proxy: Of property Object.data:
   Unable to serialize value as string | aws-cdk-lib.cloud_assembly_schema.FileAssetMetadataEntry | aws-cdk-lib.cloud_assembly_schema.ContainerImageAssetMetadataEntry | array<aws-cdk-lib.cloud_assembly_schema.Tag> | undefined
[ERROR] ├── 🛑 Failing value is a boolean
[ERROR] │      true
[ERROR] ╰── 🔍 Failure reason(s):
[ERROR]     ├─ [as string] Value is not a string
[ERROR]     ├─ [as array<aws-cdk-lib.cloud_assembly_schema.Tag>] Value is not an array
[ERROR]     ├─ [as aws-cdk-lib.cloud_assembly_schema.FileAssetMetadataEntry] Value is not an object
[ERROR]     ╰─ [as aws-cdk-lib.cloud_assembly_schema.ContainerImageAssetMetadataEntry] Value is not an object
[ERROR] @jsii/kernel.SerializationError: Of property Object.data: Unable to serialize value as string | aws-cdk-lib.cloud_assembly_schema.FileAssetMetadataEntry | aws-cdk-lib.cloud_assembly_schema.ContainerImageAssetMetadataEntry | array<aws-cdk-lib.cloud_assembly_schema.Tag> | undefined
[ERROR] ├── 🛑 Failing value is a boolean
[ERROR] │      true
[ERROR] ╰── 🔍 Failure reason(s):
[ERROR]     ├─ [as string] Value is not a string
[ERROR]     ├─ [as array<aws-cdk-lib.cloud_assembly_schema.Tag>] Value is not an array
[ERROR]     ├─ [as aws-cdk-lib.cloud_assembly_schema.FileAssetMetadataEntry] Value is not an object
[ERROR]     ╰─ [as aws-cdk-lib.cloud_assembly_schema.ContainerImageAssetMetadataEntry] Value is not an object
[ERROR]     at Object.process (/private/var/folders/jk/0lz5v5jj33g0p8x5xmyhvwz80000gn/T/jsii-java-runtime1036786840231922344/lib/program.js:10485:19)
[ERROR]     at Kernel._Kernel_fromSandbox (/private/var/folders/jk/0lz5v5jj33g0p8x5xmyhvwz80000gn/T/jsii-java-runtime1036786840231922344/lib/program.js:9465:25)
[ERROR]     at Kernel.get (/private/var/folders/jk/0lz5v5jj33g0p8x5xmyhvwz80000gn/T/jsii-java-runtime1036786840231922344/lib/program.js:8846:103)
[ERROR]     at KernelHost.processRequest (/private/var/folders/jk/0lz5v5jj33g0p8x5xmyhvwz80000gn/T/jsii-java-runtime1036786840231922344/lib/program.js:10715:36)
[ERROR]     at KernelHost.run (/private/var/folders/jk/0lz5v5jj33g0p8x5xmyhvwz80000gn/T/jsii-java-runtime1036786840231922344/lib/program.js:10675:22)
[ERROR]     at Immediate._onImmediate (/private/var/folders/jk/0lz5v5jj33g0p8x5xmyhvwz80000gn/T/jsii-java-runtime1036786840231922344/lib/program.js:10676:46)
[ERROR]     at process.processImmediate (node:internal/timers:478:21)

Notice that the data type is expected to be string | aws-cdk-lib.cloud_assembly_schema.FileAssetMetadataEntry | aws-cdk-lib.cloud_assembly_schema.ContainerImageAssetMetadataEntry | array<aws-cdk-lib.cloud_assembly_schema.Tag> | undefined.

This is because as part of the change introduced here:

expr.directCode(`this.addMetadata('${CUSTOM_RESOURCE_SINGLETON}', true)`),
expr.directCode(`this.addMetadata('${CUSTOM_RESOURCE_RUNTIME_FAMILY}', this.runtime.family)`),

The value of the data field may now be a number and boolean. But the type defined in cloud schema MetadataEntryType is not updated with these types here

export type MetadataEntryData =
  | AssetMetadataEntry // FileAssetMetadataEntry | ContainerImageAssetMetadataEntry
  | LogMessageMetadataEntry // string
  | LogicalIdMetadataEntry // string
  | StackTagsMetadataEntry; // Tag[]

Notice these are the types from the error message.

Below is a snippet of the generated manifest.json with this issue:

...
        "/dataspray-site-landing-test/Custom::CDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C": [
          {
            "type": "aws:cdk:is-custom-resource-handler-singleton",
            "data": true
          },
          {
            "type": "aws:cdk:is-custom-resource-handler-runtime-family",
            "data": 2
          },
          {
            "type": "aws:cdk:is-custom-resource-handler-singleton",
            "data": true
          },
          {
            "type": "aws:cdk:is-custom-resource-handler-runtime-family",
            "data": 2
          }
        ],
...

Note that aws:cdk:is-custom-resource-handler-singleton matches the CUSTOM_RESOURCE_SINGLETON above and aws:cdk:is-custom-resource-handler-runtime-family matches the CUSTOM_RESOURCE_RUNTIME_FAMILY above.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

CDK 2.134.0 Cloud Assembly 36.0.6

Expected Behavior

Shouldn't fail. Expected the generated manifest.json to be read properly.

Current Behavior

Fails with error.

Reproduction Steps

It's difficult to create a self-contained snippet for reproduction. It's unclear to me what conditions are met for the metadata entries to be generated.

Possible Solution

Add missing types to MetadataEntryData

Additional Information/Context

No response

CDK CLI Version

N/A

Framework Version

No response

Node.js Version

v20.11.0

OS

osx

Language

Java

Language Version

21.0.1-graalce

Other information

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.effort/mediumMedium work item – a couple days of effortp1potential-regressionMarking this issue as a potential regression to be checked by team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions