Skip to content
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

Deno hangs during S3 bucket upload when deploying with AWS CDK #27239

Open
eriklz opened this issue Dec 5, 2024 · 8 comments · May be fixed by #27381
Open

Deno hangs during S3 bucket upload when deploying with AWS CDK #27239

eriklz opened this issue Dec 5, 2024 · 8 comments · May be fixed by #27381
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@eriklz
Copy link

eriklz commented Dec 5, 2024

Version: Deno 2.1.2

AWS CDK: 2.171.1

When trying to deploy infrastructure using the cdk deploy command, the process hangs when uploading assets to the CDK deplloyment asset S3 bucket. This works fine if using Node.js.

❯ cdk deploy

✨ Synthesis time: 0.4s

my-stack: start: Building 5dc4439c955fa5cef985fdc3a01dc6df93ad4777214f12b9027aba5873263b9f:nnnnnnnnnnnn-eu-west-1
my-stack: success: Built 5dc4439c955fa5cef985fdc3a01dc6df93ad4777214f12b9027aba5873263b9f:nnnnnnnnnnnn-eu-west-1
my-stack: start: Publishing 5dc4439c955fa5cef985fdc3a01dc6df93ad4777214f12b9027aba5873263b9f:nnnnnnnnnnnn-eu-west-1

(no progress from here...)


AWS CDK installed as global install: deno install -g --name cdk npm:aws-cdk

cdk.json:

{
  "app": "deno run -A main.ts"
}

deno.json:

{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "aws-cdk-lib": "npm:aws-cdk-lib@^2.171.1"
  }
}

main.ts:

import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as process from 'node:process';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'my-stack', {
  env: {
    account: process.env.CDK_DEFAULT_ACCOUNT,
    region: process.env.CDK_DEFAULT_REGION,
  },
});

const vpc = ec2.Vpc.fromLookup(stack, 'my-vpc', {
  isDefault: true,
});

const instance = new ec2.Instance(stack, 'my-ec2', {
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO),
  machineImage: ec2.MachineImage.latestAmazonLinux2023(),
  vpc,
});
@bartlomieju bartlomieju added bug Something isn't working correctly needs investigation requires further investigation before determining if it is an issue or not node compat triage required 👀 Deno team needs to make a decision if this change is desired labels Dec 6, 2024
@gdtroszak
Copy link

FWIW, this behavior started for me at CDK v2.167.0. Perhaps the biggest change was the transition from using aws-sdk v2 to v3.

@gdtroszak
Copy link

gdtroszak commented Dec 13, 2024

I believe the issue indeed has to do with some interaction with the @aws-sdk/client-s3, specifically because of a recent update to the @smithy/node-http-handler dependency around how it handles expect request headers with 100-continue.

I've created a repo the reproduces the problem and demonstrates that using a prior version of @smithy/node-http-handler works.

@roseMix
Copy link

roseMix commented Dec 15, 2024

@gdtroszak Thanks, your solution worked for me.
I've had the same issue with @aws-sdk/client-s3 changing @smithy/node-http-handler version to 3.3.1 in deno.lock worked!

@devsnek devsnek linked a pull request Dec 16, 2024 that will close this issue
@Yohe-Am
Copy link

Yohe-Am commented Jan 8, 2025

While @gdtroszak 's solution works in some cases, it doesn't apply to all s3 APIs with some failing with

TypeError [ERR_INVALID_ARG_TYPE]: The first argume
nt must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of File
    at _from (ext:deno_node/internal/buffer.mjs:217:9)
    at Function.from (ext:deno_node/internal/buffer.mjs:229:10)
    at writeBody (file:///home/yohe/.local/share/ghjk/deno/npm/registry.npmjs.org/@smithy/node-http-handler/3.3.1/dist-cjs/index.js:189:28)
    at writeRequestBody (file:///home/yohe/.local/share/ghjk/deno/npm/registry.npmjs.org/@smithy/node-http-handler/3.3.1/dist-cjs/index.js:170:5)
    at eventLoopTick (ext:core/01_core.js:214:9) {
  code: "ERR_INVALID_ARG_TYPE",
  name: "TypeError",
  toString: [Function (anonymous)],
  "$metadata": { attempts: 1, totalRetryDelay: 0 }
}

Eagerly awaiting #27381 to land. You folks know any other workaround?

@taseenb
Copy link

taseenb commented Jan 9, 2025

This still fails in Deno 2.1.4 but works in Node:

import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3'

const s3 = new S3Client({
  ...
})

const uploadObject = async () => {
  try {
    const command = new PutObjectCommand({
      Bucket: BUCKET_NAME,
      Key: OBJECT_KEY,
      Body: OBJECT_CONTENT,
    })
    console.log('Uploading object...')

    const response = await s3.send(command)

    console.log('Upload successful:', response)
  } catch (error) {
    console.error('Error uploading object:', error)
  }
}

uploadObject()

I spent an entire day debugging this issue, and it turns out the problem lies with Deno. Unfortunately, this was the last thing I thought could be causing it.

This fails without errors, which is the scariest part.

@taseenb
Copy link

taseenb commented Jan 9, 2025

Temporary fix for Deno 2.1.4:

import { S3Client } from '@aws-sdk/client-s3'
import { NodeHttpHandler } from 'npm:@smithy/[email protected]' // DOWNGRADE HERE

const s3 = new S3Client({
  requestHandler: new NodeHttpHandler(),
})

@devsnek devsnek removed needs investigation requires further investigation before determining if it is an issue or not triage required 👀 Deno team needs to make a decision if this change is desired labels Jan 14, 2025
@Yohe-Am
Copy link

Yohe-Am commented Jan 22, 2025

@taseenb what version of client-s3 is it that worked with [email protected] for you? I tried a few versions but I'm still seeing the TypeError from above.

Edit: nvm. Looks like I was already using 3.3.1 when I encountered the TypeError at first.

@taseenb
Copy link

taseenb commented Jan 22, 2025

3.726.1 works

Later versions seem to have issues, but haven't tried again recently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants