diff --git a/src/HealthChecks.Publisher.CloudWatch/CloudWatchOptions.cs b/src/HealthChecks.Publisher.CloudWatch/CloudWatchOptions.cs index dd4fa2d305..e30305a185 100644 --- a/src/HealthChecks.Publisher.CloudWatch/CloudWatchOptions.cs +++ b/src/HealthChecks.Publisher.CloudWatch/CloudWatchOptions.cs @@ -1,4 +1,5 @@ using Amazon; +using Amazon.CloudWatch; namespace HealthChecks.Publisher.CloudWatch; @@ -19,4 +20,14 @@ public class CloudWatchOptions /// The namespace for the metric data. /// public string Namespace { get; set; } = "Xabaril/AspNetCoreDiagnosticsHealthChecks"; + + /// + /// Delegate to build used by AWS CloudWatch publisher. + /// + public Func ClientBuilder { get; set; } = options => + { + return options.AwsAccessKeyId is null && options.AwsSecretAccessKey is null && options.Region is null + ? new AmazonCloudWatchClient() + : new AmazonCloudWatchClient(options.AwsAccessKeyId, options.AwsSecretAccessKey, options.Region); + }; } diff --git a/src/HealthChecks.Publisher.CloudWatch/CloudWatchPublisher.cs b/src/HealthChecks.Publisher.CloudWatch/CloudWatchPublisher.cs index 3d711bc093..f4ecc4d363 100644 --- a/src/HealthChecks.Publisher.CloudWatch/CloudWatchPublisher.cs +++ b/src/HealthChecks.Publisher.CloudWatch/CloudWatchPublisher.cs @@ -18,7 +18,7 @@ public CloudWatchPublisher(CloudWatchOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); - _amazonCloudWatchClient = new AmazonCloudWatchClient(options.AwsAccessKeyId, options.AwsSecretAccessKey, options.Region); + _amazonCloudWatchClient = options.ClientBuilder(options); string serviceCheckName = options.ServiceCheckName ?? Assembly.GetEntryAssembly()?.GetName()?.Name ?? "undefined"; diff --git a/src/HealthChecks.Publisher.CloudWatch/DependencyInjection/CloudWatchHealthCheckBuilderExtensions.cs b/src/HealthChecks.Publisher.CloudWatch/DependencyInjection/CloudWatchHealthCheckBuilderExtensions.cs index 0d63b22e6e..79239b2b86 100644 --- a/src/HealthChecks.Publisher.CloudWatch/DependencyInjection/CloudWatchHealthCheckBuilderExtensions.cs +++ b/src/HealthChecks.Publisher.CloudWatch/DependencyInjection/CloudWatchHealthCheckBuilderExtensions.cs @@ -9,7 +9,7 @@ public static class CloudWatchHealthCheckBuilderExtensions /// Add a health check publisher for AWS CloudWatch. /// /// - /// For each published a new metric is sent to AWS CloudWatch indicating + /// For each published a new metric is sent to AWS CloudWatch indicating /// the health check status (2 - Healthy, 1 - Degraded, 0 - Unhealthy) /// /// The . diff --git a/test/HealthChecks.Publisher.CloudWatch.Tests/HealthChecks.Publisher.CloudWatch.approved.txt b/test/HealthChecks.Publisher.CloudWatch.Tests/HealthChecks.Publisher.CloudWatch.approved.txt index 96506b1450..b5fb10e1a3 100644 --- a/test/HealthChecks.Publisher.CloudWatch.Tests/HealthChecks.Publisher.CloudWatch.approved.txt +++ b/test/HealthChecks.Publisher.CloudWatch.Tests/HealthChecks.Publisher.CloudWatch.approved.txt @@ -5,6 +5,7 @@ namespace HealthChecks.Publisher.CloudWatch public CloudWatchOptions() { } public string? AwsAccessKeyId { get; set; } public string? AwsSecretAccessKey { get; set; } + public System.Func ClientBuilder { get; set; } public string Namespace { get; set; } public Amazon.RegionEndpoint? Region { get; set; } public string? ServiceCheckName { get; set; }