AWS S3 get object using URL

Viewed 11077

I have a collection of URLs that may or may not belong to a particular bucket. These are not public.

I'm using the nodejs aws-sdk to get them.

However, the getObject function needs params Bucket and Key separately, which are already in my URL.

Is there any way I can use the URL?

I tried extracting the key by splitting URL with / and getting bucket by splitting with .. But the problem is the bucket name can also have . and I'm not sure if key name can have / as well.

2 Answers

use this module parse-s3-url to set the parameter for the getObject.

 bucket.getObject( parseS3Url('https://s3.amazonaws.com/mybucket/mykey'), (err:any, data:any) =>{
    if (err) {
      // alert("Failed to retrieve an object: " + error);
    } else {
      console.log("Loaded " + data.ContentLength + " bytes");
      // do something with data.Body
    }
  });
Related