I had been using Amplify version 4, I am currently updating Amplify to versioni 6. With in my code I need a signed URL for my websocket connection to be established. I have a cognito user and use the credentials to create the signed URL.
My original code:
const userCredentials = await Auth.currentUserCredentials();
const accessInfo = {
access_key: userCredentials.accessKeyId,
secret_key: userCredentials.secretAccessKey,
session_token: userCredentials.sessionToken,
};
//- Sign Url
return Signer.signUrl(sourceUrl, accessInfo);
This would return a string signed URL.
Signer was a part of Amplify version 4 but I no longer have access to it in version 6. This is causing problems in my websocket connection since I can not get back the correct signed URL.
I am currently trying to user the following code but the URL I get back is wrong and is not a string.
const {
tokens,
credentials,
identityId,
userSub
} = await fetchAuthSession();
const url = new URL(sourceUrl);
// Create an HttpRequest from the URL
const request = new HttpRequest({
method: 'GET', // or 'PUT' if you are uploading to S3 for example
protocol: url.protocol,
hostname: url.hostname,
path: url.pathname,
headers: {
'host': url.hostname
}
});
const signer = new SignatureV4({
credentials: credentials,
region: 'us-east-1',
service: 'execute-api',
sha256: Sha256
});
const signedRequest = await signer.sign(request);
Is there a way to get a signed URL the same way as Amplify version 4?
Christian Seyoum is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.