ottokruse / s3-spa-upload

Upload a single page application to S3 with the right content-type and cache-control meta-data
23 stars 4 forks source link

Add option to set bucket region explicitly #6

Closed tripplilley closed 1 year ago

tripplilley commented 1 year ago

Because the JS SDK v3 is more strict, it fails if the bucket region doesn't match whatever's in the current environment (see below). While I (eventually) figured out that I can override my profile's region by explicitly setting the env var during the call (AWS_REGION=<region> s3-spa-upload [...]), it would be nice to have a CLI option to set it. I presume it would also be helpful for programmatic callers, but that's not a current use case I have.

$ s3-spa-upload . sbx-docsite-exp-s3bucket-1ch9nsuef1s5z --prefix toprint/
Upload started of 10 files (with concurrency: 100)
/Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8
    const response = new exceptionCtor({
                     ^

PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
    at throwDefaultError (/Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8:22)
    at deserializeAws_restXmlPutObjectCommandError (/Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:5782:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
    at async /Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:14:20
    at async /Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/middleware-retry/dist-cjs/retryMiddleware.js:27:46
    at async /Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/flexibleChecksumsMiddleware.js:58:20
    at async /Users/tlilley/projects/veatech/docs/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:7:26
    at async uploadToS3 (/Users/tlilley/projects/veatech/docs/node_modules/s3-spa-upload/src/index.js:72:5) {
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 301,
    requestId: '0DKDQ167P7NTE4B0',
    extendedRequestId: 'JkKBadiSXqyi2qZ1Giqu4e+FMnLB39r6YK50OJm20Sd57wUiXRDpPQCZq2iUIaOv3e30YAe8EH2nDXqsG3IPNA==',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  Code: 'PermanentRedirect',
  Endpoint: 's3.amazonaws.com',
  Bucket: 'sbx-docsite-exp-s3bucket-1ch9nsuef1s5z',
  RequestId: '0DKDQ167P7NTE4B0',
  HostId: 'JkKBadiSXqyi2qZ1Giqu4e+FMnLB39r6YK50OJm20Sd57wUiXRDpPQCZq2iUIaOv3e30YAe8EH2nDXqsG3IPNA=='
}

Node.js v19.8.1
ottokruse commented 1 year ago

Thanks again for the report, and work around. Need to figure out why the V3 sdk does this. Bit annoying to have to pass the region explicitly

ottokruse commented 1 year ago

Fixed in v2.1.0

Happy coding!