Skip to content

Commit

Permalink
Add DynamoDBOptions.Limit and DynamoDBOptions.LastEvaluatedTableName
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r committed Jul 22, 2023
1 parent fabbaf4 commit 81a21ef
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IHealthChecksBuilder AddDynamoDb(

return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => new DynamoDbHealthCheck(options),
_ => new DynamoDbHealthCheck(options),
failureStatus,
tags,
timeout));
Expand Down
15 changes: 14 additions & 1 deletion src/HealthChecks.DynamoDb/DynamoDbHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using System.Collections.Generic;

Check failure on line 1 in src/HealthChecks.DynamoDb/DynamoDbHealthCheck.cs

View workflow job for this annotation

GitHub Actions / build

Using directive is unnecessary.
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using Amazon.Runtime;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.DynamoDb;

/// <summary>
/// Health check for AWS DynamoDb database.
/// </summary>
public class DynamoDbHealthCheck : IHealthCheck
{
private readonly DynamoDBOptions _options;

/// <summary>
/// Creates health check for AWS DynamoDb database with the specified options.
/// </summary>
/// <param name="options"></param>
public DynamoDbHealthCheck(DynamoDBOptions options)
{
_options = Guard.ThrowIfNull(options);
Expand Down Expand Up @@ -36,7 +45,11 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
? CreateClientWithCredentials(credentials)
: CreateClientWithoutCredentials();

_ = await client.ListTablesAsync(cancellationToken).ConfigureAwait(false);
var request = new ListTablesRequest { ExclusiveStartTableName = _options.LastEvaluatedTableName };
if (_options.Limit != null)
request.Limit = _options.Limit.Value;

var response = await client.ListTablesAsync(request, cancellationToken).ConfigureAwait(false);

return HealthCheckResult.Healthy();
}
Expand Down
10 changes: 10 additions & 0 deletions src/HealthChecks.DynamoDb/DynamoDbOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ public class DynamoDBOptions
public string? SecretKey { get; set; }

public RegionEndpoint RegionEndpoint { get; set; } = null!;

/// <summary>
/// A maximum number of table names to read.
/// </summary>
public int? Limit { get; set; }

/// <summary>
/// The first table name to read.
/// </summary>
public string? LastEvaluatedTableName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace HealthChecks.DynamoDb
"d")]
public string? AccessKey { get; set; }
public Amazon.Runtime.AWSCredentials? Credentials { get; set; }
public string? LastEvaluatedTableName { get; set; }
public int? Limit { get; set; }
public Amazon.RegionEndpoint RegionEndpoint { get; set; }
[System.Obsolete("Specify access key and secret as a BasicCredential to Credentials property instea" +
"d")]
Expand Down

0 comments on commit 81a21ef

Please sign in to comment.