Skip to main content

Custom wrapper connection to AWS Lambda

Comments

5 comments

  • Kate Larson Community moderator Principal Technical Writer
    Celigo University Level 3: Master

    David Bobek - Thanks for posting to the Community in case others can offer advice. I see you are also working with our Support team, which is great. I just wanted to let you know the Documentation team will also follow that Support ticket and enhance the documentation per any specific recommendations that result. 

    0
  • Scott Henderson CTO
    Answer Pro
    Top Contributor

    In case it helps, we have a Node.js open source framework that you can use for implementing Lambda extensions.  For imports specifically, it should be as simple as implementing this function signature.

    Please note that you are given an array of records in the postMapData variable, and then you need to return an array of the same length with the results of the import.  i.e. if you are given 2 records in the postMapData variable, then you should return the following to tell integrator.io that both records were imported correctly. 

    return callback(null, [ {statusCode: 200}, {statusCode: 200} ])

    I highly recommend reading both of these README files. 

    1. https://github.com/celigo/integrator-extension/blob/master/README.md
    2. https://github.com/celigo/lambda-integrator-extension/blob/master/README.md

    The above frameworks use Node.js, but if you are using a different programming language, then the above frameworks could still be helpful to reverse engineer the HTTP request and response structures used.  Ultimately, these are just HTTP calls, and any programming language that can implement the same request and response structures should work.

    0
  • Simon Camilleri

    Signing the requests canonically would definitely work, but you could also simply place api gateway infront of the lambda, attach an authoriser and make a very nice and plain http request with your auth token.

    0
  • David Bobek

    Hello Scott,

    Thanks for reply, we actually read those samples that you are providing, also as one additional directly SQS wrapper: https://github.com/CeligoServices/SQSWrapper/tree/dependabot/npm_and_yarn/aws-sdk-2.814.0

     

    what we are able to do is really process the data as we intend, however defining the response is bit tricky, we are using the exact number of the objects in array, however still getting mismatch, even when in integrator we do not include any hooks or something like that.

    please see the sample of the code:

    exports.handler = async (event) => {
        // TODO implement
        console.info("Event\n" + JSON.stringify(event.body, null, 2))
            var data = event.data[0].data
        //var data = event.data
        console.info("request Count\n" + data.length)
        var resp = []
        for (var i=0;i<data.length;i++){
            //console.info("EventS\n" + JSON.stringify(data[i], null, 2))
            resp.push({
                statusCode: 200,
                ignored: false,
                errors:[],
                id:""
            })
        }
        console.info("Response Count\n" + resp.length)
        const response = {
            statusCode: 200,
            body: {}
        };

        return resp;
        //return response;
    };

     

    From the logs we are tracking the number of results in array:

     
    2022-02-09T10:21:51.296+01:00 2022-02-09T09:21:51.217Z 2c6ee7a3-b8d7-4b0e-8005-5004636b06c6 INFO request Count 3665
     
    2022-02-09T10:21:51.297+01:00

    2022-02-09T09:21:51.237Z 2c6ee7a3-b8d7-4b0e-8005-5004636b06c6 INFO Response Count 3665

    as you can see we are sending an array of exactly the same number of objects as it is in request. and we tried multiple representations.

     

    All the time getting back as: 

    Extension result doesn't contain the same number of elements as the request object.
     

    So we are sending what you are actually advising, but not getting success.

    0
  • Scott Henderson CTO
    Answer Pro
    Top Contributor

    Curious if support was able to help you solve the issue?  It is difficult to say what went wrong from your code. 

    For example, I see the following lines of code, but I am not sure how these relate to the array 'postMapData' that contains the exact records sent to your wrapper from integrator.io.  Your code needs to return postMapData.length, but again, not sure what is in event.data[0].data or event.data.

    var data = event.data[0].data

    //var data = event.data

    0

Please sign in to leave a comment.