Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getFailedExecutionMessage = async (inputMessage) => {
try {
const executionArn = getMessageExecutionArn(inputMessage);
const { events } = await StepFunctions.getExecutionHistory({ executionArn });
const stepFailedEvents = events.filter(
(event) =>
['ActivityFailed', 'LambdaFunctionFailed'].includes(event.type)
);
if (stepFailedEvents.length === 0) {
log.info(`No failed step events found in execution ${executionArn}`);
return inputMessage;
}
const lastStepFailedEvent = stepFailedEvents[stepFailedEvents.length - 1];
const failedStepExitedEvent = getStepExitedEvent(events, lastStepFailedEvent);
if (!failedStepExitedEvent) {
log.info(
`Could not retrieve output from last failed step in execution ${executionArn}, falling back to execution input`,