zirkelc / amazon-s3-url

Format and parse Amazon S3 URL
https://www.npmjs.com/package/amazon-s3-url
1 stars 0 forks source link

Doesn't account for Access Point URLs #1

Closed shellscape closed 5 months ago

shellscape commented 5 months ago

Given an access point url like https://shotstack-api-stage-output.s3-ap-southeast-2.amazonaws.com/mcy75psxhd/batman.mp4 the package throws an error that the url format isn't recognized. It would be cool if that were supported.

zirkelc commented 5 months ago

This package currently only supports the regular endpoints, but not the Access Point and Control endpoints. However, I can add that easily.

Just one thing to clarify before I start, because I haven't used S3 Access Point yet. According to this table, the right format of Amazon S3 Access Point endpoints should be <access-point>.s3-accesspoint.<region>.amazonaws.com/<key>.

So in your case, the right URL should be:

https://shotstack-api-stage-output.s3-accesspoint.ap-southeast-1.amazonaws.com/mcy75psxhd/batman.mp4

But that's different form the one you provided. Yours looks like a regular virtual-hosted style URL in the format of <bucket-name>.s3.<region>.amazonaws.com/<key>.

There is a slightly difference in that you used a - character instead of a . between s3 and the region ap-southeast-2: s3-ap-southeast-2. This is an older style that only works for some regions, see this section. Here is more information on that: https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#s3-dash-region

You should be able to change the URL from s3-ap-southeast-2 to s3.ap-southeast-2 and it will work with this package.

shellscape commented 5 months ago

Unfortunately that's coming from a third party service and isn't something we can enforce.

zirkelc commented 5 months ago

Okay, that's fine. I can adapt the implementation to support this type of format. Are you using this library to parse the bucket and key from the given URL or what is your use case?

shellscape commented 5 months ago

Yes we're parsing the bucket (in this case the ap name), the region, and key for use with a CopyObjectCommand

zirkelc commented 5 months ago

I created PR #2 that should fix the parsing for this kind of URLs.

2024-04-04_17-00-26

Could you please verify it by installing the alpha package:

npm install amazon-s3-url@alpha

If it works for you, I will release it.

zirkelc commented 5 months ago

Hi @shellscape I did some more tests and released a new version. Let me know if this solved your problem.