@vendia/aws-signed-fetch
v0.1.0
Published
Call AWS endpoints via fetch with sig v4
Downloads
178
Keywords
Readme
Signed AWS requests
Isomorphic sig v4 requests
import { createSignedFetcher } from '@vendia/aws-signed-fetch'
async function getCredentials() {
// Your logic to get valid AWS creds
return {
accessKeyId: 'xyz',
secretAccessKey: '123',
sessionToken: 'abc'
}
}
// Create aws sigv4 signed fetch client
const signedFetch = createSignedFetcher({
method: 'POST',
region: 'us-east-1',
baseUrl: 'https://your-api-url.com',
getCredentials: getCredentials,
debug: true
})
// Call https://lolololololollolololo.com/nice with signed GET
signedFetch('/nice').then((d) => {
console.log('d', d.data)
}).catch((e) => {
console.log('err', e)
})
// Call https://lolololololollolololo.com/nice with signed POST
signedFetch('/nice', {
method: 'POST',
body: JSON.stringify({
wow: 'cool'
})
}).then((d) => {
console.log('d', d.data)
}).catch((e) => {
console.log('err', e)
})