Skip to content

Commit d897679

Browse files
authored
Fix SignatureDoesNotMatch error when SecretsManager enabled (#650)
* update listener.ts * nit
1 parent dab10b2 commit d897679

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/metrics/listener.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,24 @@ export interface MetricsConfig {
6363

6464
export 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}`);

0 commit comments

Comments
 (0)