Vote count: 0
I can't use the Node aws-sdk because it depends on the http library which is not available to me in React Native.
I'm trying to use axios and react-native-aws-signature to craft a request to this AWS API endpoint: http://ift.tt/2lvcxeV
I'm getting a 403: Missing Authentication Token from AWS.
Here's my attempt:
var axios = require('axios');
var AWSSignature = require('react-native-aws-signature');
var awsSignature = new AWSSignature();
var date = awsSignature.formatDateTime(new Date(Date.now()).toISOString());
var body = JSON.stringify({
logGroupName: 'xxx',
logStreamName: 'production',
limit: 30,
startFromHead: false
}, null, 0);
var host = `logs.ap-southeast-2.amazonaws.com`;
var headers = {
Host: host,
'X-Amz-Date': date,
'region': 'ap-southeast-2',
Connection: 'Keep-Alive',
'Content-Length': body.length,
Accept: 'application/json',
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'Logs_20140328.GetLogEvents',
};
var options = {
path: '/',
method: 'post',
service: 'logs',
headers,
region: 'ap-southeast-2',
body,
credentials: {
SecretKey: 'xxx',
AccessKeyId: 'xxx'
}
};
awsSignature.setParams(options);
var authorization = awsSignature.getAuthorizationHeader();
var headersWithAuth = headers;
headersWithAuth['Authorization'] = authorization;
axios.post(`https://${host}/`, body, headersWithAuth).then(response => {
console.log(response.data);
}).catch(err => {
console.log(err);
});
Been experimenting all night -- very frustrating. Thanks for any help.
asked 19 secs ago
Difficulty making AWS GetLogEvents API call in a Node application
Aucun commentaire:
Enregistrer un commentaire