Skip to content

Commit 9121ac4

Browse files
authored
fix: skip API key retrieval when extension is running (#680)
Move getAPIKey call to avoid unnecessary Secrets Manager calls when Datadog Lambda Extension is present, preventing Signature expired errors in provisioned concurrency environments.
1 parent ac0116f commit 9121ac4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/metrics/listener.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ export class MetricsListener {
7474
}
7575

7676
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-
8477
if (this.isExtensionRunning === undefined) {
8578
this.isExtensionRunning = await isExtensionRunning();
8679
logDebug(`Extension present: ${this.isExtensionRunning}`);
@@ -98,6 +91,12 @@ export class MetricsListener {
9891
return;
9992
}
10093

94+
// We get the API key in onStartInvocation rather than in the constructor because in busy functions,
95+
// initialization may occur more than 5 minutes before the first invocation (due to proactive initialization),
96+
// resulting in AWS errors: https://github.com/aws/aws-sdk-js-v3/issues/5192#issuecomment-2073243617
97+
if (!this.apiKey) {
98+
this.apiKey = this.getAPIKey(this.config);
99+
}
101100
this.currentProcessor = this.createProcessor(this.config, this.apiKey);
102101
}
103102

0 commit comments

Comments
 (0)