Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

aws-s3-assets: Asset publish fails on files with no extension if outputType is BundlingOutput.SINGLE_FILE #30471

Closed
TwoNull opened this issue Jun 6, 2024 · 4 comments · Fixed by #30597
Assignees
Labels
@aws-cdk/aws-s3-assets @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@TwoNull
Copy link

TwoNull commented Jun 6, 2024

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

@TwoNull TwoNull added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 6, 2024
@TwoNull TwoNull changed the title aws-s3-assets: Asset bundling fails on files with no extension if outputType is BundlingOutput.SINGLE_FILE aws-s3-assets: Asset publish fails on files with no extension if outputType is BundlingOutput.SINGLE_FILE Jun 6, 2024
@pahud pahud self-assigned this Jun 11, 2024
@pahud
Copy link
Contributor

pahud commented Jun 11, 2024

Yes I can reproduce this. It doesn't have to be a golang app, just generate a file under /asset-output.

export class AssetTestStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
      super(scope, id, props);

      const asset = new s3assets.Asset(this, 'asset', {
          path: path.join(__dirname, '../assets/main'),
          bundling: {
              image: DockerImage.fromRegistry('golang:1.21'),
              entrypoint: ["bash", "-c"],
              // command: ["echo 123 > /asset-output/main"], // this won't work
              command: ["echo 123 > /asset-output/main.bin"], // this works
              outputType: BundlingOutput.SINGLE_FILE,
          },
      });
      new CfnOutput(this, 'AssetHash', { value: asset.assetHash });
  }
}

Error message

dummy-stack: fail: EISDIR: illegal operation on a directory, read

@pahud pahud added p1 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 11, 2024
@pahud pahud removed their assignment Jun 11, 2024
@sakurai-ryo
Copy link
Contributor

It seems to be caused by a mismatch between the contents of AssetManifest and the path of the file to be uploaded.
I will try to fix it.

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
@aws-cdk/aws-s3-assets @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants