Skip to content

Commit fb6d2dc

Browse files
authored
fix: gracefully handle an error retrieving auth info from AWS Secrets Manager (#401)
* fix: gracefully handle an error retrieving auth info from AWS Secrets Manager If there is an error retrieving an APM auth secret from AWS Secrets Manager (attempted when ELASTIC_APM_SECRETS_MANAGER_API_KEY_ID or ELASTIC_APM_SECRETS_MANAGER_SECRET_TOKEN_ID are provided), then the extension will now *log a warning* rather than erroring out. This allows the Lambda function to still work. Only the reporting of APM server data will fail (with a 403). This was already the behavior for an invalid ELASTIC_APM_SECRET_TOKEN.
1 parent b72a64f commit fb6d2dc

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

CHANGELOG.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
2323
https://github.com/elastic/apm-aws-lambda/compare/v1.4.0...main[View commits]
2424
25+
[float]
26+
===== Bug fixes
27+
- Log a warning, instead of failing a Lambda function, if auth retrieval from AWS Secrets Manager fails. Reporting APM data will not work, but the Lambda function invocations will proceed. {lambda-pull}401[401]
28+
2529
[float]
2630
[[lambda-1.4.0]]
2731
=== 1.4.0 - 2023/05/03

app/aws.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,24 @@ func loadAWSOptions(ctx context.Context, cfg aws.Config, logger *zap.SugaredLogg
3636
if apmServerApiKeySMSecretId, ok := os.LookupEnv("ELASTIC_APM_SECRETS_MANAGER_API_KEY_ID"); ok {
3737
result, err := loadSecret(ctx, manager, apmServerApiKeySMSecretId)
3838
if err != nil {
39-
return "", "", fmt.Errorf("failed loading APM Server ApiKey from Secrets Manager: %w", err)
39+
logger.Warnf("Could not load APM API key from AWS Secrets Manager. Reporting APM data will likely fail. Is 'ELASTIC_APM_SECRETS_MANAGER_API_KEY_ID=%s' correct? See https://www.elastic.co/guide/en/apm/lambda/current/aws-lambda-secrets-manager.html. Error message: %v", apmServerApiKeySMSecretId, err)
40+
apmServerApiKey = ""
41+
} else {
42+
logger.Infof("Using the APM API key retrieved from AWS Secrets Manager.")
43+
apmServerApiKey = result
4044
}
41-
42-
logger.Infof("Using the APM API key retrieved from Secrets Manager.")
43-
apmServerApiKey = result
4445
}
4546

4647
apmServerSecretToken := os.Getenv("ELASTIC_APM_SECRET_TOKEN")
4748
if apmServerSecretTokenSMSecretId, ok := os.LookupEnv("ELASTIC_APM_SECRETS_MANAGER_SECRET_TOKEN_ID"); ok {
4849
result, err := loadSecret(ctx, manager, apmServerSecretTokenSMSecretId)
4950
if err != nil {
50-
return "", "", fmt.Errorf("failed loading APM Server Secret Token from Secrets Manager: %w", err)
51+
logger.Warnf("Could not load APM secret token from AWS Secrets Manager. Reporting APM data will likely fail. Is 'ELASTIC_APM_SECRETS_MANAGER_SECRET_TOKEN_ID=%s' correct? See https://www.elastic.co/guide/en/apm/lambda/current/aws-lambda-secrets-manager.html. Error message: %v", apmServerSecretTokenSMSecretId, err)
52+
apmServerSecretToken = ""
53+
} else {
54+
logger.Infof("Using the APM secret token retrieved from AWS Secrets Manager.")
55+
apmServerSecretToken = result
5156
}
52-
53-
logger.Infof("Using the APM secret token retrieved from Secrets Manager.")
54-
apmServerSecretToken = result
5557
}
5658

5759
return apmServerApiKey, apmServerSecretToken, nil

0 commit comments

Comments
 (0)