Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class TestBucketDeploymentData extends Stack {
// Test empty string handling
const file8 = Source.data('file8.txt', '');

// Test null JSON data value
const file9 = Source.jsonData('my-json/config-with-null.json', { hello: "there", goodbye: null })

const deployment = new BucketDeployment(this, 'DeployWithDataSources', {
destinationBucket: this.bucket,
sources: [file1, file2],
Expand All @@ -77,6 +80,7 @@ class TestBucketDeploymentData extends Stack {
deployment.addSource(file6);
deployment.addSource(file7);
deployment.addSource(file8);
deployment.addSource(file9);

new CfnOutput(this, 'BucketName', { value: this.bucket.bucketName });
}
Expand Down Expand Up @@ -105,6 +109,17 @@ assertionProvider.expect(ExpectedResult.objectLike({
Body: '{"secret_value":"test\\"with\\"quotes"}',
}));

// Assert that JSON data with a null value is represented properly
const jsonNullAssertionProvider = integTest.assertions.awsApiCall('S3', 'getObject', {
Bucket: testCase.bucket.bucketName,
Key: path.join('deploy/here', 'my-json/config-with-null.json'),
});

// Verify the content is valid JSON and both null and non-null fields are present
jsonNullAssertionProvider.expect(ExpectedResult.objectLike({
Body: '{"hello":"there","goodbye":null}',
}));

// Add assertions to verify the YAML file
const yamlAssertionProvider = integTest.assertions.awsApiCall('S3', 'getObject', {
Bucket: testCase.bucket.bucketName,
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-s3-deployment/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class Source {
return obj.map(v => Source.escapeTokens(scope, v));
}

if (typeof obj === 'object') {
if (obj !== null && typeof obj === 'object') {
Copy link
Copy Markdown
Member

@Abogical Abogical Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Object.fromEntries(
Object.entries(obj).map(([key, value]) => {
// As JSON keys are always strings, keys are assumed to be either regular strings or string tokens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,7 @@ test('Source.jsonData() can be used to create a file with a JSON object', () =>

const config = {
foo: 'bar',
baz: null,
sub: {
hello: bucket.bucketArn,
},
Expand All @@ -1441,7 +1442,7 @@ test('Source.jsonData() can be used to create a file with a JSON object', () =>
});

const result = app.synth();
expect(readDataFile(result, 'app-config.json')).toBe('{"foo":"bar","sub":{"hello":<<marker:0xbaba:0>>},"<<marker:0xbaba:1>>":"Token can be a key as well!"}');
expect(readDataFile(result, 'app-config.json')).toBe('{"foo":"bar","baz":null,"sub":{"hello":<<marker:0xbaba:0>>},"<<marker:0xbaba:1>>":"Token can be a key as well!"}');

// verify marker is mapped to the bucket ARN in the resource props
Template.fromJSON(result.stacks[0].template).hasResourceProperties('Custom::CDKBucketDeployment', {
Expand Down
Loading