1
votes

I'm working on a facebook chat bot, and I'm developing it using the serverless framework (Node.js) and deploying it to aws lambda. For the first few weeks, I just ran a local serverless lambda simulator using the serverless offline plugin and everything was working great. Yesterday, I finally decided to deploy it to AWS lambda, and now I see a significant drop in performance and consistency. Sometimes the bot takes 10 seconds to respond and sometimes it is instantaneous. The weird part is, on the lambda cloud logs, it always says the function completes in around 150 ms, which seems super fast, but the facebook bot simply doesn't mirror that speed. I am hitting a database, but the queries are definitely not taking anywhere near 10 seconds to run.

UPDATE:

I decided to try to test the bot my manually sending requests to the API endpoint using postman (which is basically curl). Every time the api responded instantly, even when I send the exact same request body that the messenger does. So it seems like the request is just taking a long time to reach the lambda api, but when it gets there it runs as it should. Any ideas of how to fix this?

3
If you trigger the lambda a few times in a row (based on a cold start of no invocations for ~20 minutes prior), is it only the first invocation that takes a long time to start up? - Trent Bartlem
@TrentBartlem Unfortunately no, regardless of whether the trigger is a cold start or not, the lambda sometimes runs very slow (and sometimes very fast) - Brandon

3 Answers

2
votes

If the API is responding quickly to your curl request, then the problem isn't on AWS end. Try matching when you send your request via Facebook to your app and when your app recieves it.

If it's getting held up on Facebooks end, Im afraid there isnt much you can do to solve it.

0
votes

Another issue could be the datacenter your lambda is running in versus where facebook is. For example, using chkutil.com, you can see facebook.com seems particularly slow from the Asia-Pacific datacenters.

enter image description here

0
votes

As it turns out, Facebook was experiencing DNS issues and has since remedied the issue.