Search code examples
node.jsamazon-s3amazon-ecs

ECS S3 Upload Hang


 const object = new PutObjectCommand({
      Bucket: s3Bucket,
      Key: key,
      Body: fileData,
      ACL: acl,
    });
    const { $metadata } = await this.s3.send(object)

I am writing an upload function for my project. The above code work perfectly on my local, local-run docker image. However, once I run my image on the ECS with same access key and secret, it just hang there with no error message. The service on ECS can access to RDS, the only problem is uploading the file to s3. I do not set up any private subnet in my VPC, im sure my s3 is able to upload. Any Idea?

I tried no matter aws-sdk v2 and v3. Tried a totally public s3 bucket. Works on local and local-runs image. But not on ECS


Solution

  • It sounds like you have your ECS task running in public subnets of your VPC, but you probably don't have public IPs assigned to your tasks. You need to enable public IP assignments in your ECS task definition. If you don't want to do that, you could add an S3 Gateway VPC Endpoint to your VPC.