-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Function does not returns until all aSync ends #2747
Comments
Hey @malikasinger1 thanks for bringing this up. It seems like your var request = require('request');
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
}) So your code should look something like this: module.exports.functionOne = (event, context, cb) => {
requestModule.post({ uri: 'https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/functionTwo' }, (error, response, body) => {
if (error) {
throw new Error(error);
}
cb(null, "done functionOne");
});
}; It's best to use the Let us know if this helps you or if you still face problems. |
Sorry @malikasinger1, but you can't achieve what you want, at least not in this way. When you call another function using What you could do is to call
Why is this hacky? Because you can't abort immediately. You need to wait a few milliseconds for the request to be received in the other server, but there is no way to know exactly when it happens. If you know that the second Lambda will run for 2 minutes, you could add a Why don't you place the Another workaround would be to call a SNS topic from |
|
Hey @malikasinger1 I'm closing this issue as it's not directly related to Serverless. Feel free to continue the discussion. |
@pmuens my issue is still not solved, please don't mark issue as close |
@malikasinger1, this issue is related with Lambda, Node-Request and Slack, but it's not related with the Serverless Framework. I believe that Stack Overflow is the best place to receive help about this issue. You could ask another question there being more specific about the Slack API. |
@zanon-io great effort, appreciable |
@malikasinger1, yes, I've tested. It returns immediately. However, I'm using Lambda-proxy and my callback is: const response = {
statusCode: 200,
body: JSON.stringify({ "message": "done functionOne" })
};
cb(null, response); Since Lambda-proxy is the default now and it requires that you use this format, your issue can be related with this. Read more about Lambda-proxy here: https://serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-proxy-integration |
@zanon-io can you please tell me what version of serverless you are using? |
I don't remember which version I was using when this question was created. Probably v1.1, but you should always use the latest stable version. Currently, it's v1.4 |
Function does not returns until all aSync ends
I want to make a function which call an api(third party) and return immediately but it is waiting for api response, here is code sample
Moreover, if i try to call
context.succeed()
instead ofcb()
it even prevent api call and function return immediately without calling apii have also asked a question on stackoverflow, any help will be appreciated
Additional Data
The text was updated successfully, but these errors were encountered: