Skip to content

Error with Custom Endpoints and S3 Client #4061

@nevil2

Description

@nevil2

Checkboxes for prior research

Describe the bug

Upgrading to v3.183 and beyond makes createPresignedPost return wrong URL. e.g. https://ams3.digitaloceanspaces.com rather than correct url (as per v3.154) of https://ams3.digitaloceanspaces.com/{bucket}.

With v3.154, I have previously raised issue (#3885 still open) that the S3client gets corrupted and starts adding the bucket twice. e.g. https://{bucket}.ams3.digitaloceanspaces.com/{bucket}/filename

I tested yesterday uploading file to Digital Ocean spaces with both POST (with details from createPresignedPost) and PUT (with URL from getSignedUrl with PutObjectCommand) yesterday.

With v3.183, Digital Ocean rejected POST but upload with PUT worked correctly.
With v3.154, Digital Ocean upload with POST worked correctly, but with PUT, the file ended up within in the bucket in {bucket}/{directory}/{filename}.

Digital Ocean have confirmed that no changes have been made which might affect this behaviour.

It is clear that changes to the way endpoints are handled have been made to @AWS-SDK libraries between v3.154 and v3.183. I do not know whether the 'double' bucket issue is solved with v3.183 (as it appears randomly, sometimes after several weeks), but it clear that a new problem has been introduced.

SDK version number

@AWS-SDK @3.183.0+, client-s3, s3-presigned-post, s3-request-presigner

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node v18

Reproduction Steps

Create Client

const s3main = new S3Client({
  endpoint: 'https://ams3.digitaloceanspaces.com',
  region: 'ams3',
  credentials: {
    accessKeyId: CloudStorage.accessKeyId,
    secretAccessKey: CloudStorage.secretAccessKey
  }
})

Get URL and details for POST upload

const { url, fields } = await createPresignedPost(s3main, {
  Bucket: bucket,
  Key: filename,
  Expires: signedUrlExpireSeconds,
  Fields: { acl },
  Conditions: [
    { success_action_status: '201' },
    { 'Content-Type': contentType }
  ]
})

Get URL for PUT upload

const command = new PutObjectCommand({ Bucket, Key, ContentType })
const url = await getSignedUrl(s3main, command, { expiresIn: signedUrlExpireSeconds })

Observed Behavior

with v3.183.0 Get URL and details for POST upload:
url = 'https://ams3.digitaloceanspaces.com'

with v3.154 Get URL for PUT upload:
url = https://{bucket}.ams3.digitaloceanspaces.com/{bucket}/filename

Expected Behavior

with v3.154.0 Get URL and details for POST upload:
url = 'https://ams3.digitaloceanspaces.com/{bucket}'

with v3.183 Get URL for PUT upload:
url = https://{bucket}.ams3.digitaloceanspaces.com/filename

Note that because v3.183 Get URL for PUT upload worked correctly once, it does not guarantee that error will not develop over time.

Possible Solution

Building workaround (recreate client, use PUT vs POST, hard code endpoint for POST, etc) into my code is pointless if behaviour keeps changing with new versions and hence code keeps failing.

Additional Information/Context

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions