-
Notifications
You must be signed in to change notification settings - Fork 4.5k
aws-s3-assets: Asset publish fails on files with no extension if outputType is BundlingOutput.SINGLE_FILE #30471
Description
Describe the bug
I'm using S3 Assets to build an executable which is downloaded on my AL2023 EC2 instances and run at startup. UNIX executables commonly have no file extension, so I named my output file main. Since there is only 1 output file, I used the SINGLE_FILE outputType. After bundling completes but before the asset is uploaded, cdk deploy will fail with the exception EISDIR: illegal operation on a directory, read.
Expected Behavior
The bundled asset should have uploaded to S3 successfully. I am able to upload the asset from the cdk.out temporary directory to S3 via the console without issue.
Current Behavior
The following is the cdk deploy output:
Bundling asset AssetTestStack/asset/Stage...
✨ Synthesis time: 6.15s
AssetTestStack: start: Building 9282ebaea97fbf485dc50bbffd97ef346bb60994b53468da7becca020a3dbbb0:current_account-current_region
AssetTestStack: success: Built 9282ebaea97fbf485dc50bbffd97ef346bb60994b53468da7becca020a3dbbb0:current_account-current_region
AssetTestStack: start: Publishing 9282ebaea97fbf485dc50bbffd97ef346bb60994b53468da7becca020a3dbbb0:current_account-current_region
AssetTestStack: start: Building 2ea762ee87d2dc20644f7ffe229b3f751c9831030044b4761eaef6d4688761d3:current_account-current_region
AssetTestStack: success: Built 2ea762ee87d2dc20644f7ffe229b3f751c9831030044b4761eaef6d4688761d3:current_account-current_region
AssetTestStack: start: Publishing 2ea762ee87d2dc20644f7ffe229b3f751c9831030044b4761eaef6d4688761d3:current_account-current_region
AssetTestStack: fail: EISDIR: illegal operation on a directory, read
AssetTestStack: success: Published 2ea762ee87d2dc20644f7ffe229b3f751c9831030044b4761eaef6d4688761d3:current_account-current_region
❌ Deployment failed: Error: Failed to publish asset 2ea762ee87d2dc20644f7ffe229b3f751c9831030044b4761eaef6d4688761d3:current_account-current_region
at Deployments.publishSingleAsset (/usr/local/lib/node_modules/aws-cdk/lib/index.js:445:11645)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.publishAsset (/usr/local/lib/node_modules/aws-cdk/lib/index.js:445:197443)
at async /usr/local/lib/node_modules/aws-cdk/lib/index.js:445:181344
Failed to publish asset 2ea762ee87d2dc20644f7ffe229b3f751c9831030044b4761eaef6d4688761d3:current_account-current_region
Interestingly, the key of the asset that failed is incorrect. 2ea762ee87d2dc20644f7ffe229b3f751c9831030044b4761eaef6d4688761d3 is the CloudFormation template JSON which uploaded to S3 successfully (as per the Published message). 9282ebaea97fbf485dc50bbffd97ef346bb60994b53468da7becca020a3dbbb0 is the asset which bundled successfully but failed to upload.
Reproduction Steps
The following is a stack I created to isolate the issue. In this case, the asset is a Go module located at /assets/main but any code that compiles to a single file should produce the same result.
import { Construct } from 'constructs';
import * as cdk from 'aws-cdk-lib';
import * as s3a from 'aws-cdk-lib/aws-s3-assets'
export class AssetTestStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const asset = new s3a.Asset(this, 'asset', {
path: './assets/main',
bundling: {
image: cdk.DockerImage.fromRegistry('golang:1.21.5'),
entrypoint: ["bash", "-c"],
command: ["GOARCH=arm64 GOOS=linux go build -o /asset-output/main ."],
outputType: cdk.BundlingOutput.SINGLE_FILE,
},
});
}
}
Possible Solution
Changing the name of the output file to main.bin fixed the issue, but it took me a while to figure out what was causing this error since I had multiple S3 assets in the stack where I originally encountered this issue. I would assume the error comes down to the CDK incorrectly parsing a file with no extension as a directory.
Additional Information/Context
No response
CDK CLI Version
2.144.0 (build 5fb15bc)
Framework Version
No response
Node.js Version
Node.js v18.17.1
OS
MacOS 12.6
Language
TypeScript
Language Version
TypeScript (5.4.5)
Other information
No response