Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gracefully handle an error retrieving auth info from AWS Secrets Manager #401

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

https://github.com/elastic/apm-aws-lambda/compare/v1.4.0...main[View commits]

[float]
===== Bug fixes
- 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]

[float]
[[lambda-1.4.0]]
=== 1.4.0 - 2023/05/03
Expand Down
18 changes: 10 additions & 8 deletions app/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,24 @@ func loadAWSOptions(ctx context.Context, cfg aws.Config, logger *zap.SugaredLogg
if apmServerApiKeySMSecretId, ok := os.LookupEnv("ELASTIC_APM_SECRETS_MANAGER_API_KEY_ID"); ok {
result, err := loadSecret(ctx, manager, apmServerApiKeySMSecretId)
if err != nil {
return "", "", fmt.Errorf("failed loading APM Server ApiKey from Secrets Manager: %w", err)
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)
apmServerApiKey = ""
} else {
logger.Infof("Using the APM API key retrieved from AWS Secrets Manager.")
apmServerApiKey = result
}

logger.Infof("Using the APM API key retrieved from Secrets Manager.")
apmServerApiKey = result
}

apmServerSecretToken := os.Getenv("ELASTIC_APM_SECRET_TOKEN")
if apmServerSecretTokenSMSecretId, ok := os.LookupEnv("ELASTIC_APM_SECRETS_MANAGER_SECRET_TOKEN_ID"); ok {
result, err := loadSecret(ctx, manager, apmServerSecretTokenSMSecretId)
if err != nil {
return "", "", fmt.Errorf("failed loading APM Server Secret Token from Secrets Manager: %w", err)
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)
apmServerSecretToken = ""
} else {
logger.Infof("Using the APM secret token retrieved from AWS Secrets Manager.")
apmServerSecretToken = result
}

logger.Infof("Using the APM secret token retrieved from Secrets Manager.")
apmServerSecretToken = result
}

return apmServerApiKey, apmServerSecretToken, nil
Expand Down