Hi all,
I have been trying (for a couple of days now) to correctly set up a way to receive the results of an asynchronous Amazon API Gateway call using a custom-built (by me) server-side action plugin. For a brief synopsis of what exactly I mean (with respect to Amazon’s asynchronous call), see this link.
I have a file that I’m uploading from a FileUploader element that I then send to an Amazon API that I’ve built. This has worked flawlessly for months for the synchronous version, but I cannot figure out how to get the asynchronous version to return the data back to me, and I really need to make the asynchronous version work. I’ve spent hours upon hours reading all sorts of comments from some of the more sophisticated Bubblers on the Plugin Development board (@sudsy, @keith, @vini_brito), but nothing I’ve tried has worked.
More specifically, I have been able to set up a context.request() call that is able to successfully hit my API, but it doesn’t wait for the results. That code looks like this:
var options = {
uri: 'https://<someAmazonAWSCall>.amazonaws.com/beta/<someAPIEndpoint>',
method: 'POST',
headers: {'X-Api-Key': '<Some API Key>'},
body: properties.fileLocation
};
const objects = context.request(options);
return {
"values": objects
}
But as soon as I try to use the context.async() function with a callback, I don’t even see anything hitting my gateway. At this point I’ve exhausted the literature in the forum, and I’m far beyond my depth (as somebody who isn’t a serious programmer, but who can get around some relatively hairy concepts as needed).
For the asynchronous side of things, I’ve tried a couple of things:
return context.async( async callback => {
try {
let parsed = await https.request("<someAWSAPI>.amazonaws.com/beta/<someAPIEndpoint>",
{
method: "POST",
body: properties.fileLocation,
headers: {"X-Api-Key": "<some API Key>"}
}
);
callback( undefined, {
subject : parsed.values
});
}
catch ( err ) {
callback( err );
}
});
as well as (in this case, requiring ‘node-fetch’; copy/pasted, so apologies if parens don’t line up/match perfectly):
return context.async( async callback => {
try {
let parsed = await fetch('https://<someAWSAPI>.amazonaws.com/beta/<someAPIEndpoint>', {
method: 'POST',
body: {"fileLocation":properties.fileLocation},
headers: { 'X-Api-Key': '<some API Key>' }
}
)
;
callback( undefined, {
subject : parsed.values
});
}
catch ( err ) {
callback( err );
}
});
If someone can point me in the right direction here, I would be exceptionally grateful.