https://serverless-stack.com/ logo
#help
Title
# help
s

satish venkatakrishnan

03/21/2022, 9:01 AM
Is there a example for creating preSigned url for S3
m

manitej

03/21/2022, 9:02 AM
using aws-sdk?
r

Ross Coundon

03/21/2022, 9:11 AM
You just need to use a lambda that has the correct get or put privileges to the bucket where the file is/will be. Then it’s as simple as (using sdk v3)
Copy code
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';

const getObjectParams: GetObjectCommandInput = {
      Bucket: bucket,
      Key: filename,
};
// or
const putObjectParams: PutObjectCommandInput = {
      Bucket: bucket,
      Key: filename,
};
const command = new GetObjectCommand(getObjectParams)
//or
const command = new PutObjectCommand(putObjectParams);


const s3Client = new S3Client({ // your config - e.g. region});
getSignedUrl(s3Client, command, { expiresIn: 3600 });
s

satish venkatakrishnan

03/21/2022, 9:15 AM
Yes I tried the similar one and I am getting the following error in postman <Code>SignatureDoesNotMatch</Code>
I might be missing something simple . But not sure on what is that
Also is there any example of giving permissions to Lambda
m

manitej

03/21/2022, 9:18 AM
I think you forgot to add
Copy code
api.attachPermissions([s3]);
r

Ross Coundon

03/21/2022, 9:18 AM
Make sure you’re using PUT to write a file (not POST)
I’ve typically done it within the lambda definition as
Copy code
permissions: [theS3Bucket]
s

satish venkatakrishnan

03/21/2022, 9:32 AM
Added permissions and getting the same error
m

manitej

03/21/2022, 9:33 AM
lambda method is
PUT
right?
s

satish venkatakrishnan

03/21/2022, 9:38 AM
Will that matter, Its a Post method .
r

Ross Coundon

03/21/2022, 10:01 AM
You might need to do some additional work to support POST - https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html