Search code examples
amazon-web-servicesaws-sdk

AWS client-s3 getSignedUrl equivalent


My client are currently getting access to some objects with getSignedUrlPromise from the package aws-sdk. The request are done from the backend and the signed url is returned to the client, everything is fine.

I'm now trying to migrate from aws-sdk to @aws-sdk/client-s3. I'd like to keep to same structure, but i can't find such command in the documentation.

I'm pretty sure @aws-sdk/client-s3 is capable of returning a signed url

Are there any (non - hacky) ways to do it ?

EDIT: Relying on this, i should use @aws-sdk/s3-request-presigner on top of @aws-sdk/client-s3 to get presigned urls.


Solution

  • You can use @aws-sdk/s3-request-presigner. For example:

    const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
    const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
    
    const clientParams = { region: "us-east-1" };
    const getObjectParams = { Bucket: "mybucket", Key: "dogs/snoopy.png" };
    
    const client = new S3Client(clientParams);
    const command = new GetObjectCommand(getObjectParams);
    const url = await getSignedUrl(client, command, { expiresIn: 3600 });
    console.log(url);