Extracting bucket and key from S3 url

170 Views Asked by At

In order to delete a file from S3 with given a file url like https://user-files.s3.us-east-1.amazonaws.com/1234-5678/image.png, is there a way to delete the file using the url?

If bucket and key are a must, is there an official way to extract them from the URL?

I dont want to assume anything about the url because if in the future ill use forcePathStyle the url will look differently (it will look like s3.us-east-1.amazonaws.com/user-files/1234-5678/image.png, and in this case the bucket name doesnt resides in the hostname). So trying to avoid string manipulations (e.g url.hostname.split(".")[0]).

0

There are 0 best solutions below