1

I have a script that works locally but does not work once I put it on Lambda.

There are two functions: playerStatsForAllGamesForPreviousDay and previousDaysGames.

...

const previousDaysGames = async () => {

    const full_games = await axios(
        {
            method: 'get',
            url: `https://api-nba-v1.p.rapidapi.com/games/date/${oneDayBefore}`,
            headers: {
                'x-rapidapi-host': 'api-nba-v1.p.rapidapi.com',
                "x-rapidapi-key": 'XXXXXXX'
            }
        }
    ).then((res)=>res.data.api.games.map(game=>game.gameId)).catch(err=>console.log('ERROR',err))

    return full_games
}

....

const playerStatsForAllGamesForPreviousDay = async () => {
    console.log('playerStatsForAllGamesForPreviousDay')
    let gameIds = await previousDaysGames()
    console.log(gameIds)
    let promises = []

    gameIds.map( async (v)=> {
        promises.push(playerStatsForSpecificGameForPreviousDay(v))
    })

    return Promise.all(promises)
        .then((results) => {
            const flattenedResults = [].concat.apply([], results)
            return flattenedResults
        })
        .catch((errors) => {
            console.log(errors)
        })
}

...

There is more to the script then these two functions, but the script runs until playerStatsForAllGamesForPreviousDay calls previousDaysGames; once this happens, the script doesn't go past this point specifically, it doesn't go past const full_games = await axios ; I can tell it doesn't go past this point, because I've put console.logs and deployed to Lambda and looked at the CloudWatch logs.

There is nothing that is returned for an error from the logs, which makes this difficult, and I'm interested in finding out more ways to debug and if anyone has an idea of a solution.

schoenbl
  • 663
  • 2
  • 14
  • 29
  • does this help? https://stackoverflow.com/questions/28449363/why-is-this-http-request-not-working-on-aws-lambda – d_bhatnagar Feb 22 '20 at 07:03
  • 1
    it put me in a direction that I wasn't thinking about that ultimately solved the issue. it was a very useful clue, and I appreciate it – schoenbl Mar 08 '20 at 03:54
  • @schoenbl how do you resolve this issue? Can you guide us? – Dipak Oct 19 '22 at 06:45
  • @Dipak sorry, but i don't remember. message me directly if you'd like. i'm guessing you found some type of solution by now. did you check the node version on lambda and make sure there wasn't a timeout issue? – schoenbl Nov 10 '22 at 06:53

0 Answers0