-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathpowertoolsCustomFunction.ts
31 lines (26 loc) · 1.08 KB
/
powertoolsCustomFunction.ts
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
import { fromBase64 } from '@aws-lambda-powertools/commons/utils/base64';
import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes';
import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
import { Logger } from '@aws-lambda-powertools/logger';
import { brotliDecompressSync } from 'node:zlib';
const logger = new Logger();
// prettier-ignore
class CustomFunctions extends PowertoolsFunctions {
@PowertoolsFunctions.signature({ // (1)!
argumentsSpecs: [['string']],
variadic: false,
})
public funcDecodeBrotliCompression(value: string): string { // (2)!
const encoded = fromBase64(value, 'base64');
const uncompressed = brotliDecompressSync(encoded);
return uncompressed.toString();
}
}
export const handler = async (event: { payload: string }): Promise<void> => {
const message = extractDataFromEnvelope<string>(
event,
'Records[*].decode_brotli_compression(notification) | [*].powertools_json(@).message',
{ customFunctions: new CustomFunctions() }
);
logger.info('Decoded message', { message });
};