How to use AWS S3 health check method provided by AspNetCore.Diagnostics.HealthChecks library
Asked Answered
B

2

5

AWS S3 health check is one of the built-in health check services provided by .NET Core. It is available in AspNetCore.HealthChecks.Aws nuget package and presumably can be used like the following code snippet:

public void ConfigureServices(IServiceCollection services)
{
  services.AddHealthChecks().AddS3("WHAT SHOULD GO HERE");
}

After searching a lot, I could not find an example or a sample displaying its usage, even on Microsoft's website.

This is a ASP.NET Core Web API project written in c#.

Bolten answered 20/5, 2021 at 4:26 Comment(2)
I've reverted your question to its original form, as your changes had changed the scope of your question, invalidating the (correct) answer I have provided. Note that bo => bo = new S3BucketOptions { AccessKey = "bob"; } (your code) and bo => bo.AccessKey = "bob" do very different things.Vidicon
I've created a demo to show you the difference between what I'm doing here (bucketOptions => bucketOptions.AccesKey = "hello") and what you were doing in your revised question code (bucketOptions => bucketOptions = new S3bucketOptions { AccessKey = "hello" };).Vidicon
V
6

For starters, AspNetCore.HealthChecks.Aws is a third party library and certainly isn't provided by Microsoft.

Looking at the code for the AddS3 extension method, it seems that you're expected to provide a configuration for S3BucketOptions:

services.AddHealthChecks().AddS3(bucketOptions => 
{
    bucketOptions.AccessKey = "hello";
    // etc
});

Source for S3BucketOptions

Vidicon answered 20/5, 2021 at 4:36 Comment(6)
I update my question and made it more descriptive, with the actual exception.Bolten
@Bolten Please try my answer. Your updated code isn't equivalent to this.Vidicon
IS there any similar API provided by AWS?Necessaries
@DixitSingla Do you mean health checks originating from AWS? It sounds like there might be from having a quick Google - I certainly saw something mentioned for ELB - but I haven't used AWS in some time so I can't confirm.Vidicon
We are adding aws service for s3 using iam role.In the healthcheck we need to check if the client is successfully created. the one provided by AspNetCore we need to pass the secret keys which we don't want to do. I have googled it but did not find the any. May be I am searching the wrong way.Necessaries
We are adding aws service for s3 using iam role.In the health check we need to check if the client is successfully created. The one provided by AspNetCore required to pass the secret keys which we don't want to do. I have googled it but did not find the any. May be I am searching the wrong way.Necessaries
L
2

You need to provide following configurations:

.AddS3(o => 
{ 
   o.AccessKey = "Your Access Key"; 
   o.SecretKey = "Your Secret Key";
   o.BucketName = "Your Bucket Name";
   o.S3Config = new();
});
Liponis answered 8/6, 2023 at 1:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.