Reputation: 3876
I am using the AWS SDK for Java to invoke some AWS Lambda functions that have been uploaded previously. The invokeAsync method returns an invokeAsyncResult object, which seems to include only a very limited set of properties and methods. In particular, the only relevant information contained in the object is the HTTP status code (e.g., 202
for success). There does not seem to be any properties of methods for retrieving the error code or the message that are supplied to the Lambda Node.js context.done()
method.
As such, there is no way to directly get any "return values" from the Lambda function invocation. I have to let the Lambda handler put an object to S3 to store a JSON representation of the return value and then use the Java SDK code to get the content of the object at the consumer side.
Does anybody know of a way to directly get some meaningful "return values" from the Lambda function?
Upvotes: 2
Views: 4878
Reputation: 1145
In your code, you can look at the results from the lambda invocation:
lambda.invoke(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
console.log(data); // successful response
if (data.Payload != '{}') {
var jdata = JSON.parse(data.Payload);
console.log(jdata.something);
successCallback(jdata);
}
else successCallback(null);
}
});
In your Lambda function, you can have something like this:
dynamodb.getItem(params, function(err, data) {
if (err) {
console.log(err);
context.fail(err);
} else {
console.log(data);
context.succeed(data);
}
}
You can also replace context.succeed() by context.done() context.succeed(null, data);
In the case I describe, the data.Payload will be a JSON string retrieved from DynamoDB.
Upvotes: 2