File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -63,18 +63,24 @@ export interface MetricsConfig {
63
63
64
64
export class MetricsListener {
65
65
private currentProcessor ?: Promise < any > ;
66
- private apiKey : Promise < string > ;
66
+ private apiKey ? : Promise < string > ;
67
67
private statsDClient : LambdaDogStatsD ;
68
68
private isExtensionRunning ?: boolean = undefined ;
69
69
private globalTags ?: string [ ] = [ ] ;
70
70
71
71
constructor ( private kmsClient : KMSService , private config : MetricsConfig ) {
72
- this . apiKey = this . getAPIKey ( config ) ;
73
72
this . config = config ;
74
73
this . statsDClient = new LambdaDogStatsD ( ) ;
75
74
}
76
75
77
76
public async onStartInvocation ( _ : any , context ?: Context ) {
77
+ // We get the API key in onStartInvocation rather than in the constructor because in busy functions,
78
+ // initialization may occur more than 5 minutes before the first invocation (due to proactive initialization),
79
+ // resulting in AWS errors: https://github.com/aws/aws-sdk-js-v3/issues/5192#issuecomment-2073243617
80
+ if ( ! this . apiKey ) {
81
+ this . apiKey = this . getAPIKey ( this . config ) ;
82
+ }
83
+
78
84
if ( this . isExtensionRunning === undefined ) {
79
85
this . isExtensionRunning = await isExtensionRunning ( ) ;
80
86
logDebug ( `Extension present: ${ this . isExtensionRunning } ` ) ;
You can’t perform that action at this time.
0 commit comments