I am learning Lambda and trying to migrate my local app to a AWS lambda.
It is very simple. Just a function which calls a external service.
My handler method call this method:
export const addTrack = async (token: string, parameters: any) => {
const url: string = process.env.URL as string
const headers = { ...globalHeaders, "authorization": "Bearer " + token };
try {
console.log("PARAMS:", parameters);
let response = await axios.put(url, parameters, { headers })
console.log('RESPONSE:', response.status + " | " + response.statusText + " | " + parameters.date + " | " + parameters.hours + " | " + parameters.comments)
} catch (e) {
console.error('Error trying to send a record:', parameters)
console.error(e)
throw new Error('Failing to call API: ' + e)
}
}
Note the console.log before and after axios.put call and alos in the catch block. I am having some intermitent logs here. Sometimes it shows, sometimes not.
The log with PARAMS always shows, so it is correct. But sometimes the RESPONSE log does not show in cloudwatch logs in any streams, but also does not show any error log.
It seems the put call is causing some error, but it do not enter in the catch block. The weird thing is sometimes when error happens in tha put call, it shows in the log.
For example, lambda is called 20 times, I have 20 PARAMS log in streams, My external services respond to 17 calls. I have only 17 RESPONSE logs and 1 errors logs. Seems 2 error logs is missing. Sometimes the external call works, but the RESPONSE log does not appear
I do not understand what is happening here. Can someone have some tips in what is happening?
I have tried to call using the .then().catch() in put call, but it does not work also.