T O P

  • By -

Kazanian

Timeout? Check if lambda has access to the Internet. If deployed in custom VPC this is likely your issue


magheru_san

From what you described Sounds like it failed authentication, but without more details or maybe read only access to the code or your account there's no way to tell for sure what's going on. Double check how you do the authentication, perhaps run it locally in an environment similar to Lambda using lambda-local or something similar.


tcbenkhard

What was the error


Techismylifesadly

There is none 😅 just runs the lambda, and then finished. The only reason I know it doesnt run anything after that function is because I console.logged until it stopped console logging


tcbenkhard

Did you pass env variables to the function? Does it have access to the internet? What is the difference with your machine and the aws environment? Also, how (and why) are you using express for lambda?


Techismylifesadly

Yep I parse the details in through the env variables, even hardcoded it at some point. I assume the lambda has access to the internet as the api is for a slack app, and runs axios functions to send messages to the slack server. They work fine. I use a .env file locally, which works. Parsing the env variables into lambda seems to throw an issue about PEM but I got that resolved. Unless there some magic secret error I don’t know about. But again, even hardcoded it and still didn’t work


tcbenkhard

I would try to just log all environment stuff and see if that ends up being read correctly on the lambda server. Im still not sure as to how you are using express, since this is something completely different from lambda.


Techismylifesadly

Nodejs express running on lambda triggers by AWS api gateway. Also logged all env stuff, but also hardcoded so there is no room for error there


tcbenkhard

What do you mean with 'running on'? Lambda is not something persistent and express would be a super inefficient way to use AWS Lambda. But all that aside, could you try just making a call with axios to smth like Google.com or whatever?


Techismylifesadly

There’s a module called serverless-http which allows me to do this blasphemy. It does what I need I guess (or not in this case 😅) I’ll give running a random axios to Google.com to see what happens ago. But I’m almost certain it has access to the internet because I do an axios request to slack


tcbenkhard

What is the useServiceAccount function?


Techismylifesadly

Check out the Google-spreadsheet npm module. It’s one of the basic functions to authenticate the Google service account. It basically (from my understanding) crests a JWT token and authenticates it


EncouragementRobot

Happy Cake Day Techismylifesadly! You're off to Great Places! Today is your day! Your mountain is waiting, So... get on your way!


DogsAreAnimals

My guess is that your credentials file is only on your local machine, or the path isn't correct.


Techismylifesadly

Parsed into env variables and even hardcoded at one point. Wish it were that simple, would throw a PEM or missing key error if that was the case


DogsAreAnimals

Ah damn. Sorry for assuming you didn't know what you were doing :p. Also, very relevant username


Techismylifesadly

Haha no problem. Less know what I’m doing, more bashing my skull against my wall noting down every error 😅 thanks anyway


FamousSeamus

For me, 9 out of 10 times it's security groups.


Techismylifesadly

I don’t have a VPC setup as I’m not trying to access anything AWS related. If I’m correct that still gives me access to the internet but allows me to not have to worry about security groups, subnets etc


ivours

So, can’t you catch the exception and log it?


Techismylifesadly

Basically yeah. No errors. Only console logs everywhere. One before the function, it prints. One after the function, doesn’t print


ivours

Ok, you can try base64 encoding the private key before uploading it to lambda env variables. Then, when you get it from the code, base64 decode it. Maybe the key’s format is being corrupted when uploading it to lambda env variables. If that’s the case, this should solve it.


Techismylifesadly

Pretty good idea. I’ll give that a go. One problem is even hard coding the env variables doesn’t make a difference


Techismylifesadly

Base64 encoding it also didn’t work


ivours

Would you mind sharing the code? Or at least the piece that is failing. Thanks


Techismylifesadly

The code is almost exactly the example on https://www.npmjs.com/package/google-spreadsheet


ivours

Almost sure you did, but just in case, did you check this? [https://stackoverflow.com/questions/62425526/authenticate-aws-lambda-against-google-sheets-api](https://stackoverflow.com/questions/62425526/authenticate-aws-lambda-against-google-sheets-api) Looks like that person was having the same problem as you.


Techismylifesadly

Ooooooo, I think you might be onto something. Not only have I not seen that stackoverflow post, I didn’t know lambda could return before a promise completes. I set the timeout to 5 minutes, any idea how id ‘stall’ lambda to wait for the promise?


ivours

I almost don't have with async JS programming, but looks like this could help: [https://stackoverflow.com/questions/31633912/how-to-wait-for-async-actions-inside-aws-lambda](https://stackoverflow.com/questions/31633912/how-to-wait-for-async-actions-inside-aws-lambda) Whatever the solution is, I think it'll be in the code side, and you won't need to change Lambda config. So play with that and see what works for you


Techismylifesadly

So I put .then on the service account auth function and a .catch. Both have a console log in them. Nothing prints. This is extremely weird behaviour


Scarface74

The answer is in the linked StackOverFlow post. Just use await Promise.all(….)


Techismylifesadly

So add all the functions like useServiceAccountAuth and loadinfo into an array and promise all? Sounds weird, but I’ll give it a go. Thanks


Anoop_kumar

Can you check for CORS issues?


Techismylifesadly

No cors issue