Is there a example for creating preSigned url for ...
# help
s
Is there a example for creating preSigned url for S3
m
using aws-sdk?
r
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
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
I think you forgot to add
Copy code
api.attachPermissions([s3]);
r
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
Added permissions and getting the same error
m
lambda method is
PUT
right?
s
Will that matter, Its a Post method .
r
You might need to do some additional work to support POST - https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html