|
| 1 | +import 'mocha'; |
| 2 | +import { expect } from 'chai'; |
| 3 | + |
| 4 | +import { fromAthena } from '../../../src/from/athena'; |
| 5 | + |
| 6 | +describe('from/athena.js', () => { |
| 7 | + it('should parse records', (done) => { |
| 8 | + fromAthena(EB_EVENT) |
| 9 | + .collect() |
| 10 | + .tap((collected) => { |
| 11 | + // console.log(JSON.stringify(collected, null, 2)); |
| 12 | + |
| 13 | + expect(collected.length).to.equal(5); |
| 14 | + expect(collected[0].event.type).to.equal('athena-query-queued'); |
| 15 | + expect(collected[1].event.type).to.equal('athena-query-running'); |
| 16 | + expect(collected[2].event.type).to.equal('athena-query-succeeded'); |
| 17 | + expect(collected[3].event.type).to.equal('athena-query-failed'); |
| 18 | + expect(collected[4].event.type).to.equal('athena-query-schedule-expired'); |
| 19 | + }) |
| 20 | + .done(done); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +export const EB_EVENT = { |
| 25 | + Records: [ |
| 26 | + { // QUEUED |
| 27 | + messageId: 'c9ebf5e9-db02-4afe-b564-971b911e9239', |
| 28 | + body: JSON.stringify({ |
| 29 | + 'version': '0', |
| 30 | + 'id': '091ec135-eb3c-cbe2-c87f-82d91c1cc230', |
| 31 | + 'detail-type': 'Athena Query State Change', |
| 32 | + 'source': 'aws.athena', |
| 33 | + 'account': '012345678912', |
| 34 | + 'time': '2026-01-26T01:12:25Z', |
| 35 | + 'region': 'us-west-2', |
| 36 | + 'resources': [], |
| 37 | + 'detail': { |
| 38 | + currentState: 'QUEUED', |
| 39 | + queryExecutionId: 'd3e31b4c-c3e9-4dbd-9cb2-38d0f33ca0f8', |
| 40 | + sequenceNumber: '1', |
| 41 | + statementType: 'DML', |
| 42 | + versionId: '0', |
| 43 | + workgroupName: 'my-lh-test-jobs-dev', |
| 44 | + }, |
| 45 | + }), |
| 46 | + attributes: { |
| 47 | + ApproximateReceiveCount: '1', |
| 48 | + SentTimestamp: '1769389945297', |
| 49 | + SenderId: 'AIDAKLMT2IB5VGAZG7DSY', |
| 50 | + ApproximateFirstReceiveTimestamp: '1769389945306', |
| 51 | + }, |
| 52 | + messageAttributes: {}, |
| 53 | + eventSource: 'aws:sqs', |
| 54 | + eventSourceARN: 'arn:aws-us-gov:sqs:us-west-2:012345678912:my-lh-test-jobs-dev-listener-eb', |
| 55 | + awsRegion: 'us-west-2', |
| 56 | + }, |
| 57 | + { // RUNNING |
| 58 | + messageId: 'dbf9ed72-fa26-4061-9b46-bd55cbd2e0de', |
| 59 | + body: JSON.stringify({ |
| 60 | + 'version': '0', |
| 61 | + 'id': '5e51fecf-a36b-237c-ce7a-7fb21dd6c4ac', |
| 62 | + 'detail-type': 'Athena Query State Change', |
| 63 | + 'source': 'aws.athena', |
| 64 | + 'account': '012345678912', |
| 65 | + 'time': '2026-01-26T01:12:26Z', |
| 66 | + 'region': 'us-west-2', |
| 67 | + 'resources': [], |
| 68 | + 'detail': { |
| 69 | + currentState: 'RUNNING', |
| 70 | + previousState: 'QUEUED', |
| 71 | + queryExecutionId: 'd3e31b4c-c3e9-4dbd-9cb2-38d0f33ca0f8', |
| 72 | + sequenceNumber: '2', |
| 73 | + statementType: 'DML', |
| 74 | + versionId: '0', |
| 75 | + workgroupName: 'my-lh-test-jobs-dev', |
| 76 | + }, |
| 77 | + }), |
| 78 | + attributes: { |
| 79 | + ApproximateReceiveCount: '1', |
| 80 | + SentTimestamp: '1769389946356', |
| 81 | + SenderId: 'AIDAKLMT2IB5VGAZG7DSY', |
| 82 | + ApproximateFirstReceiveTimestamp: '1769389946357', |
| 83 | + }, |
| 84 | + messageAttributes: {}, |
| 85 | + eventSource: 'aws:sqs', |
| 86 | + eventSourceARN: 'arn:aws-us-gov:sqs:us-west-2:012345678912:my-lh-test-jobs-dev-listener-eb', |
| 87 | + awsRegion: 'us-west-2', |
| 88 | + }, |
| 89 | + { // SUCCEEDED |
| 90 | + messageId: '8b9330ae-ccb2-40c6-a5f3-fc3338a3a9d9', |
| 91 | + body: JSON.stringify({ |
| 92 | + 'version': '0', |
| 93 | + 'id': '8bce653a-9d74-7d7a-de8b-7b80db178467', |
| 94 | + 'detail-type': 'Athena Query State Change', |
| 95 | + 'source': 'aws.athena', |
| 96 | + 'account': '012345678912', |
| 97 | + 'time': '2026-01-26T01:12:35Z', |
| 98 | + 'region': 'us-west-2', |
| 99 | + 'resources': [], |
| 100 | + 'detail': { |
| 101 | + currentState: 'SUCCEEDED', |
| 102 | + previousState: 'RUNNING', |
| 103 | + queryExecutionId: 'd3e31b4c-c3e9-4dbd-9cb2-38d0f33ca0f8', |
| 104 | + sequenceNumber: '3', |
| 105 | + statementType: 'DML', |
| 106 | + versionId: '0', |
| 107 | + workgroupName: 'my-lh-test-jobs-dev', |
| 108 | + }, |
| 109 | + }), |
| 110 | + attributes: { |
| 111 | + ApproximateReceiveCount: '1', |
| 112 | + SentTimestamp: '1769389955415', |
| 113 | + SenderId: 'AIDAKLMT2IB5VGAZG7DSY', |
| 114 | + ApproximateFirstReceiveTimestamp: '1769389955417', |
| 115 | + }, |
| 116 | + messageAttributes: {}, |
| 117 | + eventSource: 'aws:sqs', |
| 118 | + eventSourceARN: 'arn:aws-us-gov:sqs:us-west-2:012345678912:my-lh-test-jobs-dev-listener-eb', |
| 119 | + awsRegion: 'us-west-2', |
| 120 | + }, |
| 121 | + { // FAILED |
| 122 | + messageId: '8b9330ae-ccb7-40c6-a5f3-fc3338a3a9d7', |
| 123 | + body: JSON.stringify({ |
| 124 | + 'version': '0', |
| 125 | + 'id': 'abcdef00-7234-5678-9abc-def012345677', |
| 126 | + 'detail-type': 'Athena Query State Change', |
| 127 | + 'source': 'aws.athena', |
| 128 | + 'account': '012345678912', |
| 129 | + 'time': '2026-01-26T01:12:26Z', |
| 130 | + 'region': 'us-west-2', |
| 131 | + 'resources': [ |
| 132 | + ], |
| 133 | + 'detail': { |
| 134 | + athenaError: { |
| 135 | + errorCategory: 2.0, // Value depends on nature of exception |
| 136 | + errorType: 1306.0, // Type depends on nature of exception |
| 137 | + errorMessage: 'Amazon S3 bucket not found', // Message depends on nature of exception |
| 138 | + retryable: false, // Retryable value depends on nature of exception |
| 139 | + }, |
| 140 | + versionId: '0', |
| 141 | + currentState: 'FAILED', |
| 142 | + previousState: 'RUNNING', |
| 143 | + statementType: 'DML', |
| 144 | + queryExecutionId: '01234567-0123-0123-0123-012345678901', |
| 145 | + workgroupName: 'primary', |
| 146 | + sequenceNumber: '3', |
| 147 | + }, |
| 148 | + }), |
| 149 | + attributes: { |
| 150 | + ApproximateReceiveCount: '1', |
| 151 | + SentTimestamp: '1769389955415', |
| 152 | + SenderId: 'AIDAKLMT2IB5VGAZG7DSY', |
| 153 | + ApproximateFirstReceiveTimestamp: '1769389955417', |
| 154 | + }, |
| 155 | + messageAttributes: {}, |
| 156 | + eventSource: 'aws:sqs', |
| 157 | + eventSourceARN: 'arn:aws-us-gov:sqs:us-west-2:012345678912:my-lh-test-jobs-dev-listener-eb', |
| 158 | + awsRegion: 'us-west-2', |
| 159 | + }, |
| 160 | + { // schedule expired |
| 161 | + messageId: 'd1c37cb3-0afa-43ac-83d7-1c045fa013c3', |
| 162 | + body: JSON.stringify({ |
| 163 | + 'version': '0', |
| 164 | + 'id': '6e3e9f4d-8029-87d0-0e07-f3a4e0712225', |
| 165 | + 'detail-type': 'athena-query-schedule-expired', |
| 166 | + 'source': 'my-lh-test-jobs-dev', |
| 167 | + 'account': '012345678912', |
| 168 | + 'time': '2026-02-02T17:27:58Z', |
| 169 | + 'region': 'us-west-2', |
| 170 | + 'resources': [], |
| 171 | + 'detail': { type: 'athena-query-schedule-expired', pk: 'nfc-exec-wf-age-group-hsi-report', sk: '1' }, |
| 172 | + }), |
| 173 | + attributes: { |
| 174 | + ApproximateReceiveCount: '1', |
| 175 | + SentTimestamp: '1770053278876', |
| 176 | + SenderId: 'AIDAKLMT2IB5VGAZG7DSY', |
| 177 | + ApproximateFirstReceiveTimestamp: '1770053278879', |
| 178 | + }, |
| 179 | + messageAttributes: {}, |
| 180 | + eventSource: 'aws:sqs', |
| 181 | + eventSourceARN: 'arn:aws-us-gov:sqs:us-west-2:012345678912:my-lh-test-jobs-dev-listener-eb', |
| 182 | + awsRegion: 'us-west-2', |
| 183 | + }, |
| 184 | + ], |
| 185 | +}; |
0 commit comments