1

Im having a bit of trouble here with a Lambda function.

I am trying to make an API call through Axios through a lambda function. I have tested the call in Postman and I am sure that it is working.

It looks like from the cloudwatch logs that i just does not call the function at all. I am thinking that there is something wrong with my setup on AWS but I can't think what it could be.

import:

import axios from 'axios';

Function called:

 public static async refreshToken(refreshToken: string): Promise<IToken> {
        
         let headers = {
                      "Content-Type": "application/x-www-form-urlencoded",
                      "Authorization": `Basic BASE_64_ENCODED_CODE`
                    };
        
        let url = "https://api.fitbit.com/oauth2/token?grant_type=refresh_token&refresh_token=REFRESH_TOKEN"
        
         let response = await axios.post(url, null, {
                      headers
                    });
        
         return {
                    accessToken: response.data.access_token,
                    expiry: Date.now() + response.data.expires_in,
                    refreshToken: response.data.refresh_token,
                };
        
    }
mick1996
  • 516
  • 9
  • 31
  • Are you certain the entry point handler is correct? – choz Mar 11 '21 at 13:13
  • @choz thank you for your response! When you say entry point handler do you mean the URL? if so, I am sure its correct. I am also able to console.log out different messages to ensure the function is firing correctly before it hits the post. any suggestions? – mick1996 Mar 11 '21 at 14:04
  • @choz I have also tried running requests to open API's and I cannot get the axios request to fire. Please help – mick1996 Mar 11 '21 at 14:05
  • I think you might want to set loggers on each line there as this is more like a debugging question. But, I have a suspect there that `response` might be a string instead of a JSON. Therefore the code exited in your return function. – choz Mar 12 '21 at 02:48
  • Right, I'll try that now thank you for the response again! Ill get back to you with what happens – mick1996 Mar 12 '21 at 09:17
  • @choz I have tried numerous different ways now with open apis with simple GET requests and it still wont work. I looks like the AXIOS function just never is triggered :( Is there any chance do you think it is to do with the Lambda not being able to access the internet? – mick1996 Mar 12 '21 at 12:19
  • It's possible, can you check if [this post](https://stackoverflow.com/a/55267891/1627271) helps? – choz Mar 12 '21 at 13:50
  • @choz Thank you again I will give this a go! – mick1996 Mar 12 '21 at 15:25

0 Answers0