I have been battling for a few days to follow an article . This is not new to me but not my strong point.
Ive managed to get my http request working but I think I need to add auth to it. here is the code.
const axios = require('axios');
const host = 'https://search-data-ds-42456788224444444444444444.us-west-1.es.amazonaws.com';
const index = 'msgsdatastream';
const type = 'msgs';
const url = `${host}/${index}/${type}/`;
const headers = { 'Content-Type': 'application/json' };
exports.handler = async (event, context) => {
let count = 0;
for (const record of event.Records) {
const id = 1;
if (record.eventName == 'REMOVE') {
await axios.delete(url + id);
return 'Item removed';
} else {
const document = record.dynamodb.NewImage;
console.log('Adding document');
console.log(document);
await axios.put(url + id, document);
}
count += 1;
}
return `Successfully processed ${count} records.`;
};
This is inside my Lambda function
Here is the cloudwatch logs.
2021-02-05T12:52:05.386Z 13782564-f0fc-4a6d-892a-c00c9e880bd1 ERROR Invoke Error {
"message": "Request failed with status code 403",
"name": "Error",
"stack": "Error: Request failed with status code 403
at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15)
at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:260:11)
at IncomingMessage.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)",
"config": {
"url": "https://search-msgs-ds-rt5io3veb4k4m5vtglmg43frxu.us-east-1.es.amazonaws.com/msgsdatastream/msgs/1",
"method": "put",
"data": "{"Area":{"S":"Lotus"},"id":{"S":"2"},"Name":{"S":"Romano"}}",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8",
"User-Agent": "axios/0.21.1",
"Content-Length": 59
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1
}
}
I am failing forward on this one. editing as I go along. Please could you direct me in how to resolve this?
question from:
https://stackoverflow.com/questions/66063895/axios-put-request-for-elasticsearch 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…