ssm: unable to use serialized YAML string values as content for CfnDocument
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
According to the documentation for the [content property of CfnDocument](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ssm.CfnDocument.html#content), it should be able to take an object representing JSON formatted content or a String if creating a YAML based document. When trying to use a string value for content, the document fails to create
### Expected Behavior
I should be able to define a document using a YAML formatted string as content. The following code should synthesize and create the appropriate resource:
```
const ssmDoc = new ssm.CfnDocument(this, "TestSsmDoc", {
content: `---
schemaVersion: "2.2"
description: "Test SSM doc for CDK."
mainSteps:
- action: "aws:runShellScript"
name: "test"
inputs:
runCommand: |
echo "Hello, World!"
`,
name: "TestSsmDocument",
documentType: "Command",
documentFormat: "YAML",
});
```
### Current Behavior
The above code fails to synthesize with the following error:
```
CfnSynthesisError: Resolution error: Supplied properties not correct for "CfnDocumentProps"
content: "---\nschemaVersion: \"2.2\"\ndescription: \"Test SSM doc for CDK.\"\nmainSteps:\n - action: \"aws:runShellScript\"\n name: \"test\"\n inputs:\n runCommand: |\n echo \"Hello, World!\"\n" should be an 'object'.
at ValidationResult.assertSuccess (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/runtime.js:1:2707)
at convertCfnDocumentPropsToCloudFormation (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/aws-ssm/lib/ssm.generated.js:1:24518)
at CfnDocument.renderProperties (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/aws-ssm/lib/ssm.generated.js:1:18952)
at PostResolveToken.Resources (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/cfn-resource.js:1:7779)
at PostResolveToken.postProcess (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/util.js:1:1653)
at Object.postProcess (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:1205)
at DefaultTokenResolver.resolveToken (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/resolvable.js:1:1483)
at resolve (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2711)
at Object.resolve (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:1079)
at resolve (/node_modules/.pnpm/aws-cdk-lib@2.114.1_constructs@10.3.0/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2990) {
type: 'CfnSynthesisError'
}
```
If I wrap the string literal in `new String(...)`, the stack synthesizes, but does so incorrectly. It renders the context as an indexed dictionary of the string array which fails to create the resource with the error `Resource handler returned message: "Invalid request provided: Missing "schemaVersion" in the document.`:
```
Resources:
TestSsmDoc:
Type: AWS::SSM::Document
Properties:
Content:
"0": "-"
"1": "-"
"2": "-"
"3": "\n"
"4": s
"5": c
"6": h
"7": e
"8": m
"9": a
"10": V
"11": e
"12": r
"13": s
"14": i
"15": o
"16": "n"
"17": ":"
"18": " "
"19": '"'
"20": "2"
"21": "."
"22": "2"
```
### Reproduction Steps
Create a stack with the following stack and attempt to synthesize the stack:
```
import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import * as ssm from "aws-cdk-lib/aws-ssm";
export class TestStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const ssmDoc = new ssm.CfnDocument(this, "TestSsmDoc", {
content: `---
schemaVersion: "2.2"
description: "Test SSM doc for CDK."
mainSteps:
- action: "aws:runShellScript"
name: "test"
inputs:
runCommand: |
echo "Hello, World!"
`,
name: "TestSsmDocument",
documentType: "Command",
documentFormat: "YAML",
});
}
}
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.114.1 (build 02bbb1d)
### Framework Version
_No response_
### Node.js Version
v18.16.1
### OS
Mac OS X
### Language
TypeScript
### Language Version
Typescript (5.2.2)
### Other information
_No response_
Contributor guide
Research direction
Start at the CfnDocument content property and reproduce the TypeScript synthesis failure from the issue. Trace the property conversion shown in aws-cdk-lib/aws-ssm/lib/ssm.generated.js, then verify that a YAML string is emitted as valid Content and that the synthesized resource can be created as an AWS SSM document.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100