@davidbobek - 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.
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.
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.
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.
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.
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.