-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pusher hangs when calling trigger
on AWS Lambda (and other serverless environments)
#67
Comments
Any clue? |
Mine trigger but with the incorrect data. Pusher is acting really weird for me on Lambda :( As a test I re-wrote it using the rest api specs and it works just fine using the request package. |
Is this still an issue for you all? If so I'll spend some time trying to get to the bottom of it! |
AWS has upgraded their node version since I last tested, it may no longer be an issue. |
I ran the below on all 3 versions of node available on lambda at the moment (
|
Experiencing the same problem! |
I published a package that ended up working for me, I was never able to resolve the issue. |
@gcphost thanks for your response. I ended up giving your package a go, worked like a charm! |
@gcphost great work on the library! @kristiankyvik I'm still not able to reproduce this issue, are you able to share more information on what you're experiencing? It would be great to resolve it in pusher-http-node too. |
@Lessio, I tried using the pusher-http-node module to trigger an event in an lambda function running node 10. The trigger worked locally but failed when deployed to AWS. Still not understand why that was the case. |
Hi @leesio, I will try to explain my situation again, since the package I started using stopped working. I am running this in node 8. This is the code I have in my lambda:
This works locally, but once deployed on AWS lambda, stops sending events. What am I missing? |
So, running pusher.trigger() in an async handler once deployed won't work. I changed the handler to be synchronous and now the event is being sent. Any idea how this can be made to run in an async block? |
@kristiankyvik that's interesting. Does it help if you provide a callback to the trigger function and call the lambda callback inside the trigger callback? I'm imagining something like:
|
I am going through the same issue, I can't make trigger work on Lambda. The request comes back with ECONNRESET. |
You just need to promisify your trigger function: const pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET,
cluster: "us2",
useTLS: true
});
const asyncTrigger = msg => {
return new Promise((resolve, reject) => {
pusher.trigger(
'channel-name',
'event-name',
msg,
(err, req, res) => {
if (err) {
reject(err);
}
resolve(res);
}
);
});
};
const pushNotification = async msg => {
return await asyncTrigger(msg);
}; Now in your lambda function: await pushNotification("Hello, World!"); |
@farbodsalimi, yes that is exactly what I did and now it works like a charm! |
@farbodsalimi thanks, but promisifying the function also means the original request takes longer to process. That was the reason I was hoping there is a way not to wait for it to fulfill first. Interestingly, it doesn't seem to be possible on Lambda, Lambda somehow cancels the request or freeze the function. |
@benjaminbalazs What do you mean by the original request takes longer to process? If you mean you have multiple side effects, and you need to run all of them asynchronous, I don't think AWS Lambda is a good choice for you. Lambda is a simple node process, it executes your code line by line, and when it reaches the last line, it will be killed. Therefore It has no idea you have a side effect in your code and doesn't wait for that. |
Using TypeScript this worked nicely for me const triggerAsync = (channel: string, event: string, msg: any) =>
new Promise((resolve, reject) =>
pusher.trigger(channel, event, msg,
(err, _req, res) => err ? reject(err) : resolve(res)
)) |
thanks @alshdavid that worked for me! |
trigger
on AWS Lambdatrigger
on AWS Lambda (and other serverless environments)
The fix here, IMO, is:
|
See also @coetry's workaround for this issue: https://github.com/zeit/static-fun/blob/master/pages/api/save-page.ts#L57 |
What a weird bug, a nightmare to track down. thanks @alshdavid |
the same problem, any new release? |
@alshdavid Thanks a lot.......... You made my day ! 🥳 |
This should be fixed in v4.0.0 since await pusher.trigger(channel, event, data) |
❤ |
Are there any caveats to getting Pusher running in AWS Lambda? For some reason, my Lambda methods hang at the trigger call and time out.
The text was updated successfully, but these errors were encountered: