UNPKG

@cumulus/message

Version:

Utilities for building and parsing Cumulus messages

82 lines 3.67 kB
/** * Utility functions for working with AWS Step Function events/messages * * @module StepFunctions * @example * const StepFunctions = require('@cumulus/message/StepFunctions'); */ import { EventBridgeEvent } from 'aws-lambda'; import { getExecutionHistory, HistoryEvent } from '@cumulus/aws-client/StepFunctions'; import { Message } from '@cumulus/types'; /** * Given a Step Function event, replace specified key in event with contents * of S3 remote message * * @param {Message.CumulusRemoteMessage} event - Source event * @param event.replace - Cumulus message replace config * @returns {Promise<object>} Updated event with target path replaced by remote message * @throws {Error} if target path cannot be found on source event * @async * @alias module:StepFunctions */ export declare const pullStepFunctionEvent: (event: { replace?: Message.ReplaceConfig; }) => Promise<unknown>; /** * Parse step message with CMA keys and replace specified key in event with contents * of S3 remote message * * @param {CMAMessage} stepMessage - Message for the step * @param {string} stepName - Name of the step * @returns {Promise<object>} Parsed and updated event with target path replaced by remote message * @async * @alias module:StepFunctions */ export declare const parseStepMessage: (stepMessage: Message.CMAMessage, stepName: string) => Promise<Message.CumulusMessage>; /** * Searches the Execution step History for the TaskStateEntered pertaining to * the failed task Id. HistoryEvent ids are numbered sequentially, starting at * one. * * @param {HistoryEvent[]} events - Step Function events array * @param {failedStepEvent} failedStepEvent - Step Function's failed event. * @param failedStepEvent.id - number (long), Step Functions failed event id. * @returns {string} name of the current stepfunction task or 'UnknownFailedStepName'. */ export declare const getFailedStepName: (events: HistoryEvent[], failedStepEvent: HistoryEvent) => string; /** * Finds all failed execution events and returns the last one in the list. * * @param {HistoryEvent[]} events - array of AWS Stepfunction execution HistoryEvents * @returns {HistoryEvent[] | undefined} - the last lambda or activity that failed in the * event array, or an empty array. */ export declare const lastFailedEventStep: (events: HistoryEvent[]) => HistoryEvent | undefined; /** * Get message to use for publishing failed execution notifications. * * Try to get the input to the last failed step in the execution so we can * update the status of any granules/PDRs that don't exist in the initial execution * input. * * Falls back to overall execution input. * * @param {Object} inputCumulusMessage - Workflow execution input message * @param {Function} getExecutionHistoryFunction - Testing override for mock/etc of * StepFunctions.getExecutionHistory * @returns {Object} - CumulusMessage Execution step message or execution input message */ export declare const getFailedExecutionMessage: (inputCumulusMessage: Message.CumulusMessage, getExecutionHistoryFunction?: typeof getExecutionHistory) => Promise<Message.CumulusMessage | { exception: { failedExecutionStepName: string; error?: string | undefined; cause?: string | undefined; }; cumulus_meta: Message.CumulusMeta; meta: Message.Meta; payload: unknown; }>; export declare const getCumulusMessageFromExecutionEvent: (executionEvent: EventBridgeEvent<"Step Functions Execution Status Change", { [key: string]: string; }>) => Promise<Message.CumulusMessage>; //# sourceMappingURL=StepFunctions.d.ts.map