File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,18 +63,24 @@ export interface MetricsConfig {
6363
6464export class MetricsListener {
6565 private currentProcessor ?: Promise < any > ;
66- private apiKey : Promise < string > ;
66+ private apiKey ? : Promise < string > ;
6767 private statsDClient : LambdaDogStatsD ;
6868 private isExtensionRunning ?: boolean = undefined ;
6969 private globalTags ?: string [ ] = [ ] ;
7070
7171 constructor ( private kmsClient : KMSService , private config : MetricsConfig ) {
72- this . apiKey = this . getAPIKey ( config ) ;
7372 this . config = config ;
7473 this . statsDClient = new LambdaDogStatsD ( ) ;
7574 }
7675
7776 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+
7884 if ( this . isExtensionRunning === undefined ) {
7985 this . isExtensionRunning = await isExtensionRunning ( ) ;
8086 logDebug ( `Extension present: ${ this . isExtensionRunning } ` ) ;
You can’t perform that action at this time.
0 commit comments