-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws-ec2: ec2.InitFile.fromObject generates a JSON file with properties converted to string #28561
Comments
Interesting I think the unit test should have covered already. Let me verify it again. |
"AWS::CloudFormation::Init": {
"configSets": {
"default": [
"config"
]
},
"config": {
"files": {
"/tmp/first.json": {
"content": {
"integer": 10,
"string": "eleven",
"decimal": 12.12,
"boolean": true,
"array": [
1,
"two",
3.3,
false
]
},
"mode": "000644",
"owner": "root",
"group": "root"
},
"/tmp/second.json": {
"content": "{\"integer\":10,\"string\":\"eleven\",\"decimal\":12.12,\"boolean\":true,\"array\":[1,\"two\",3.3,false]}",
"encoding": "plain",
"mode": "000644",
"owner": "root",
"group": "root"
}
}
}
}
Looks like |
However, looking at the cfn-init document and its samples
Looks like for some reason the JSON object written to file through cfn-init would always convert all types to string and it's CFN's behavior. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html I'll create an internal ticket for clarifying. |
internal tracking: V1185649309 |
OK we have some insight from the relevant teams. We probably need to improve the CFN document but at this moment for cloudformation template in JSON formate, if you need to persist the data types you will need to serialize it like
And that falls into your fromString() case:
We should clarify it in CDK doc. |
Describe the bug
When creating files in an EC2 instance during CloudFormation Init, if using
ec2.InitFile.fromObject()
, than the JSON fields are converted to string. For example, the objectIs converted to
Expected Behavior
File content generated by
ec2.InitFile.fromObject()
to be similar to:{"integer":10,"string":"eleven","decimal":12.12,"boolean":true,"array":[1,"two",3.3,false]}
Current Behavior
File content is like:
{"boolean": "true", "string": "eleven", "integer": "10", "array": ["1", "two", "3.3", "false"], "decimal": "12.12"}
Reproduction Steps
In a new CDK project (initialized with
cdk init app --language typescript
):Possible Solution
No response
Additional Information/Context
Here are the files section of the generated template
JSON
YAML
And here is the content of
/var/lib/cfn-init/data/metadata.json
in the instance:CDK CLI Version
2.117.0
Framework Version
2.117.0
Node.js Version
20.2.0
OS
Windows 11
Language
TypeScript
Language Version
5.3.3
Other information
There is an older issue here for the same issue, but even though it was closed, I can still reproduce the issue in 2.117.0.
The text was updated successfully, but these errors were encountered: