-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatch-config.js
More file actions
48 lines (47 loc) · 3.29 KB
/
Copy pathdispatch-config.js
File metadata and controls
48 lines (47 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Extracts the event source from the first record in the event.Records array.
* Handles both 'eventSource' (lowercase, standard in most AWS events) and
* 'EventSource' (uppercase, for backward compatibility with some AWS services).
*
* @param {Object} event - The AWS Lambda event object.
* @returns {string|undefined} The event source string (e.g., 'aws:s3', 'aws:sns'), or undefined if not found.
*/
function getRecordsSource(event) {
if (event.Records && Array.isArray(event.Records) && event.Records.length > 0) {
return event.Records[0].eventSource || event.Records[0].EventSource;
}
return undefined;
}
/**
* Ordered dispatch rules evaluated by the main handler. Each rule provides a
* `check` predicate to determine if an incoming event matches and the path to
* the handler module responsible for processing that event type. Rules are
* evaluated sequentially until a match is found.
*/
export default [
{ check: e => e.request && e.session && e.context?.System, handler: './handlers/handleAlexa.js' },
{ check: e => e.bot && e.userId && e.inputTranscript, handler: './handlers/handleLex.js' },
{ check: e => e.arguments && e.identity && e.info, handler: './handlers/handleAppSync.js' },
{ check: e => e.clientId && e.topic && e.payload, handler: './handlers/handleIoTRule.js' },
{ check: e => e.records && Array.isArray(e.records) && e.records[0]?.recordId, handler: './handlers/handleFirehose.js' },
{ check: e => e.invokingEvent && e.ruleParameters && e.resultToken, handler: './handlers/handleConfigRule.js' },
{ check: e => e.taskToken || e.source === 'aws.states', handler: './handlers/handleStepFunctions.js' },
{ check: e => e.version === '2.0' && e.requestContext?.routeKey && e.requestContext?.connectionId, handler: './handlers/handleWebSocket.js' },
{ check: e => e.type === 'TOKEN' && e.methodArn, handler: './handlers/handleAuthorizerV1.js' },
{ check: e => e.version === '2.0' && e.type === 'REQUEST', handler: './handlers/handleAuthorizerV2.js' },
{ check: e => e.version === '2.0' && e.requestContext?.http?.method, handler: './handlers/handleHttpV2.js' },
{ check: e => e.requestContext?.elb, handler: './handlers/handleAlb.js' },
{ check: e => e.httpMethod, handler: './handlers/handleHttpV1.js' },
{ check: e => e.Records && e.Records[0]?.cf, handler: './handlers/handleEdge.js' },
{ check: e => e.awslogs?.data, handler: './handlers/handleCloudWatchLogs.js' },
{ check: e => e.RequestType && e.ResponseURL, handler: './handlers/handleCustomResource.js' },
{ check: e => e.triggerSource && e.userPoolId, handler: './handlers/handleCognito.js' },
{ check: e => getRecordsSource(e) === 'aws:sqs', handler: './handlers/handleSqs.js' },
{ check: e => getRecordsSource(e) === 'aws:sns', handler: './handlers/handleSns.js' },
{ check: e => getRecordsSource(e) === 'aws:s3', handler: './handlers/handleS3.js' },
{ check: e => getRecordsSource(e) === 'aws:dynamodb', handler: './handlers/handleDynamoDB.js' },
{ check: e => getRecordsSource(e) === 'aws:kinesis', handler: './handlers/handleKinesis.js' },
{ check: e => getRecordsSource(e) === 'aws:ses', handler: './handlers/handleSes.js' },
{ check: e => e.source === 'aws.events', handler: './handlers/handleScheduled.js' },
{ check: e => e.source && e['detail-type'], handler: './handlers/handleEventBridge.js' },
];