I have 2 lambda functions, my first function w/c we'll call "PostStep" invokes another lambda function "RetryStep" asynchronously whenever a timeout occurs. It's been working fine ever since. Now I have to do some code changes, and during testing, a weird issue occurred.
Upon timeout, it still calls the RetryStep function asynchronously, but then the function is not really being invoked. I tried invoking the PostStep function again, then I noticed that's the time when the RetryStep function is really invoked, but with the previous request's data.
Here's how I'm doing the invocation:
LivePostingService.class
@Override
public void postTransaction(Transaction transaction) {
... some posting logic ...
conditionalCallRetryLambdaFunction(transaction);
}
private void conditionalCallRetryLambdaFunction(Transaction transaction) {
try {
String payload = objectMapper.writeValueAsString(transaction);
lambdaInvokerService.invokeAsync(lambdaRetryFunctionName, payload);
} catch (JsonProcessingException e) {
if(LOGGER.isErrorEnabled()) {
LOGGER.error(e.getMessage(), e);
}
}
}
LambdaInvokerService.class
@Service
public class LambdaInvokerServiceImpl implements LambdaInvokerService {
LOGGER.info("Calling lambda function: " + functionName + ", with payload: " + payload);
InvokeRequest req = new InvokeRequest()
.withFunctionName(functionName)
.withInvocationType(InvocationType.Event)
.withPayload(payload);
AsyncHandler<InvokeRequest, InvokeResult> asyncHandler = new AsyncHandler<InvokeRequest, InvokeResult>() {
@Override
public void onError(Exception e) {
LOGGER.error(e.getMessage());
}
@Override
public void onSuccess(InvokeRequest request, InvokeResult invokeResult) {
LOGGER.info("Success! " + invokeResult);
}
};
lambdaAsyncClient.invokeAsync(req, asyncHandler);
}
Here's my handler:
@Override
public Void handleRequest(DynamodbEvent dynamodbEvent, Context context) {
livePostingService.postTransaction(transaction);
return null;
}
As you can see from the code, the log Calling lambda function.. appears at the end of PostStep function, but the log Success! appears at the beginning of the PostStep function if i invoke it again.
It's the same code with what's currently on our production. I even did a git checkout on our master branch then ran it on dev, but the same issue still occurs. Do you have any idea about this?
Thanks!