S3 pre-signed url not working on whatsapp cloud Api

35 views Asked by At

My goal is to send an image from s3 via whatsapp. If i get the pre-signed url from the aws console, i can send the image as expected, i receive 200 and its shows up on the chat. But when i get the url from aws-sdk on a lambda function, i recceive 200 but the image does not appear in the chat. Both urls i can acess in any browser normally. Im testing the chat message sending in postman.

From console: https://MY_BUCKET.s3.us-east-1.amazonaws.com/%2Ftmp/MY_FILE?response-content-disposition=inline&X-Amz-Security-Token=BIG_ENCODED_TOKEN&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240329T204315Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Credential=ANOTHER_CREDENTIAL_WITH_MY_REGION&X-Amz-Signature=ANOTHER_SIGNATURE

Via sdk: https://MY_BUCKET.s3.us-east-1.amazonaws.com//tmp/MY_FILE?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ANOTHER_CREDENTIAL_WITH_MY_REGION&X-Amz-Date=20240329T194855Z&X-Amz-Expires=3600&X-Amz-Security-Token=BIG_ENCODED_TOKEN&X-Amz-Signature=ANOTHER_SIGNATURE&X-Amz-SignedHeaders=host&x-id=GetObject

My code on lambda: import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3'; import { getSignedUrl } from '@aws-sdk/s3-request-presigner';

const s3Client = new S3Client({ region: 'MY_REGION' });

export const handler = async (event) => { let params = { Bucket: 'BUCKET_NAME', Key: 'OBJECT_KEY', Expires: 3600 }; try { const command = new GetObjectCommand(params); const presignedUrl = await getSignedUrl(s3Client, command, { expiresIn: params.Expires }); return presignedUrl; } catch (error) { return error; }

};

I checked policy and roles, do i need to check something else? How can i get from the sdk the same kind of presinged url as the console, so i can send in the cloud api?

0

There are 0 answers