3

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#.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
user1451111
  • 1,735
  • 3
  • 18
  • 30
  • 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. – ProgrammingLlama May 20 '21 at 05:16
  • I've created a [demo](https://rextester.com/TQDO29633) 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" };`). – ProgrammingLlama May 20 '21 at 05:29

2 Answers2

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

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • I update my question and made it more descriptive, with the actual exception. – user1451111 May 20 '21 at 05:12
  • @user1451111 Please try my answer. Your updated code isn't equivalent to this. – ProgrammingLlama May 20 '21 at 05:14
  • IS there any similar API provided by AWS? – Dixit Singla Jan 25 '22 at 07:40
  • @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. – ProgrammingLlama Jan 25 '22 at 07:50
  • 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. – Dixit Singla Jan 25 '22 at 11:10
  • 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. – Dixit Singla Jan 25 '22 at 11:11
0

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();
});
Sakvin
  • 13
  • 3