Skip to content
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

Async Client? #25

Open
cedricbastin opened this issue Sep 4, 2020 · 2 comments
Open

Async Client? #25

cedricbastin opened this issue Sep 4, 2020 · 2 comments

Comments

@cedricbastin
Copy link

cedricbastin commented Sep 4, 2020

This sample code doesn't work in my AWS Lambda:

var client = new AWS.NodeHttpClient();
console.log("client:", client)
// returns "client: {}"

client.handleRequest(req, null, function(httpResp) {
    console.log("this never gets called")
}

This posts mentions something about an async Client but I'm not sure where to put the await?
https://stackoverflow.com/questions/60609426/aws-httpclient-handlerequest-is-not-working-in-aws-lambda

@wawo9193
Copy link

wawo9193 commented Apr 7, 2021

@cedricbastin I'm having this same issue, were you able to figure it out?

I played around with the async/await options, changed the timeout for the lambda function (cause mine is moving slightly bigger data), and still haven't figured out why. This is weird because a test event works for me when I do the S3 bucket test event, but it doesn't work when ran regularly by doing a natural event to an S3 bucket.

@cedricbastin
Copy link
Author

cedricbastin commented Apr 9, 2021

@wawo9193 I ended up using another client:

import { HttpClient, Signers } from "aws-sdk";

public postToES(record: string): Promise<any> {
    var http = new HttpClient();
    
    return new Promise((resolve, reject) => {
        http.handleRequest(
            req,
            null,
            (response: any) => {
                //do stuff
            },
            (err: any) => {
                this.log.error(err);
                reject(err);
            }
        );
    });
}

// call method:
await this.postToES(record)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants