Skip to content

aws-s3-deployment: Source.data fails for empty content #35809

@sean-xyz

Description

@sean-xyz

Describe the bug

if an empty string is given as the data parameter to Source.data, it yields an error.

populating the argument with a non-empty ("0", below) string succeeds:

new s3deploy.BucketDeployment(this, "some-object", {
	sources: [s3deploy.Source.data(`path/to/empty/object`, "0")],
	destinationBucket: bucket,
});

Regression Issue

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

Last Known Working CDK Library Version

0.2.211

Expected Behavior

successful deployment with a created s3 object

Current Behavior

deploy error:

TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at Object.writeFileSync (node:fs:2434:5)
    at Object.bind (node_modules/aws-cdk-lib/aws-s3-deployment/lib/source.js:1:2576)
    at node_modules/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.js:1:6564
    at Array.map (<anonymous>)
    at new BucketDeployment2 (node_modules/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.js:1:6545)
    at new BucketDeployment2 (node_modules/aws-cdk-lib/core/lib/prop-injectable.js:1:681)
    at new BadStack (lib/stacks/bad.ts:43:3)
    at new App (bin/cdk.ts:122:21)
    at Object.<anonymous> (bin/cdk.ts:157:1)
    at Module._compile (node:internal/modules/cjs/loader:1706:14) {
  code: 'ERR_INVALID_ARG_TYPE'

Reproduction Steps

import * as cdk from "aws-cdk-lib";
import * as s3 from "aws-cdk-lib/aws-s3";
import * as s3deploy from "aws-cdk-lib/aws-s3-deployment";

export class BadStack extends cdk.Stack {
	constructor(scope: Construct, id: string, props: StackProps) {
		super(scope, id, props);

		const bucket = new s3.Bucket(this, "bucket", {
			bucketName: "my-bucket-name",
			blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
		});

		new s3deploy.BucketDeployment(this, "empty-object", {
			sources: [s3deploy.Source.data("path/to/empty", "")],
			destinationBucket: bucket,
		});
	}
}

Possible Solution

No response

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.220.0

AWS CDK CLI version

2.1004.0 (build f0ad96e)

Node.js Version

v22.19.0

OS

nixos v25.11.20251019.5e2a59a

Language

TypeScript

Language Version

5.9.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions