@@ -2,27 +2,39 @@ import { Logger } from '../../src';
2
2
import { APIGatewayProxyEvent , Context } from 'aws-lambda' ;
3
3
import { LambdaInterface } from '@aws-lambda-powertools/commons' ;
4
4
5
- const SAMPLE_RATE = parseFloat ( process . env . SAMPLE_RATE ) ;
6
- const LOG_MSG = process . env . LOG_MSG ;
5
+ const SAMPLE_RATE = parseFloat ( process . env . SAMPLE_RATE || '0.1' ) ;
6
+ const LOG_MSG = process . env . LOG_MSG || 'Hello World' ;
7
7
8
8
const logger = new Logger ( {
9
9
sampleRateValue : SAMPLE_RATE ,
10
10
} ) ;
11
11
12
12
class Lambda implements LambdaInterface {
13
+ private readonly logMsg : string ;
14
+
15
+ public constructor ( ) {
16
+ this . logMsg = LOG_MSG ;
17
+ }
18
+
13
19
// Decorate your handler class method
14
20
@logger . injectLambdaContext ( )
21
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
+ // @ts -ignore
15
23
public async handler ( event : APIGatewayProxyEvent , context : Context ) : Promise < { requestId : string } > {
16
- logger . debug ( LOG_MSG ) ;
17
- logger . info ( LOG_MSG ) ;
18
- logger . warn ( LOG_MSG ) ;
19
- logger . error ( LOG_MSG ) ;
20
-
24
+ this . dummyMethod ( ) ;
25
+
21
26
return {
22
27
requestId : context . awsRequestId ,
23
28
} ;
24
29
}
30
+
31
+ private dummyMethod ( ) : void {
32
+ logger . debug ( this . logMsg ) ;
33
+ logger . info ( this . logMsg ) ;
34
+ logger . warn ( this . logMsg ) ;
35
+ logger . error ( this . logMsg ) ;
36
+ }
25
37
}
26
38
27
39
export const myFunction = new Lambda ( ) ;
28
- export const handler = myFunction . handler ;
40
+ export const handler = myFunction . handler . bind ( myFunction ) ;
0 commit comments