Skip to content
Draft
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: 2 additions & 2 deletions src/Benchmarks/Benchmarks/SignerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task SetupAsync()
};

var httpContent = new GetItemHttpContent(request, request.TableName, request.Key.PartitionKeyName!, request.Key.SortKeyName);
_httpRequest = new HttpRequestMessage(HttpMethod.Post, RegionEndpoint.USEast1.RequestUri)
_httpRequest = new HttpRequestMessage(HttpMethod.Post, RegionEndpoint.USEast1.BuildRequestUri(ServiceNames.DynamoDb))
{
Content = httpContent
};
Expand All @@ -52,7 +52,7 @@ public HttpRequestMessage SigningNative()
CleanupHeaders(_httpRequest);

var meta = new SigningMetadata(RegionEndpoint.USEast1, new AwsCredentials("accessKey", "secretKey"), DateTime.UtcNow,
_httpClient.DefaultRequestHeaders, null);
_httpClient.DefaultRequestHeaders, null, ServiceNames.DynamoDb);
AwsRequestSigner.Sign(_httpRequest, _contentStream, meta);

return _httpRequest;
Expand Down
40 changes: 25 additions & 15 deletions src/EfficientDynamoDb/Configs/RegionEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,46 @@ public class RegionEndpoint
private const string ChinaEndpointFormat = "https://{0}.{1}.amazonaws.com.cn"; // 0 - Service Name, 1 - Region
private const string RegularEndpointFormat = "https://{0}.{1}.amazonaws.com"; // 0 - Service Name, 1 - Region

internal const string ServiceName = "dynamodb";
// internal const string ServiceName = "dynamodb";

private readonly string? _requestUriOverride;

internal string RequestUri { get; private set; }

public string Region { get; }

public static RegionEndpoint Create(string region)
{
var format =
region.StartsWith("cn-", StringComparison.OrdinalIgnoreCase)
? ChinaEndpointFormat
: RegularEndpointFormat;

return new RegionEndpoint(region, format);
return new RegionEndpoint(region);
}

public static RegionEndpoint Create(string region, string requestUri)
{
return new RegionEndpoint(region, RegularEndpointFormat) { RequestUri = requestUri };
return new RegionEndpoint(region, requestUri);
}

public static RegionEndpoint Create(RegionEndpoint region, string requestUri)
{
return new RegionEndpoint(region.Region, RegularEndpointFormat) { RequestUri = requestUri };
return new RegionEndpoint(region.Region, requestUri);
}

private RegionEndpoint(string region, string uriFormat = RegularEndpointFormat)
private RegionEndpoint(string region)
{
Region = region;
RequestUri = string.Format(uriFormat, ServiceName, region);
}

private RegionEndpoint(string region, string requestUriOverride) : this(region)
{
_requestUriOverride = requestUriOverride;
}

internal string BuildRequestUri(string serviceName)
{
if (!string.IsNullOrEmpty(_requestUriOverride))
return _requestUriOverride;

var format = Region.StartsWith("cn-", StringComparison.OrdinalIgnoreCase)
? ChinaEndpointFormat
: RegularEndpointFormat;
return string.Format(format, serviceName, Region);
}

/// <summary>
Expand Down Expand Up @@ -122,12 +132,12 @@ private RegionEndpoint(string region, string uriFormat = RegularEndpointFormat)
/// <summary>
/// The China (Beijing) endpoint.
/// </summary>
public static RegionEndpoint CNNorth1 => new RegionEndpoint("cn-north-1", ChinaEndpointFormat);
public static RegionEndpoint CNNorth1 => new RegionEndpoint("cn-north-1");

/// <summary>
/// The China (Ningxia) endpoint.
/// </summary>
public static RegionEndpoint CNNorthWest1 => new RegionEndpoint("cn-northwest-1", ChinaEndpointFormat);
public static RegionEndpoint CNNorthWest1 => new RegionEndpoint("cn-northwest-1");

/// <summary>
/// The Europe (Frankfurt) endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal async Task BatchWriteItemAsync(BuilderNode node, CancellationToken canc
{
using var httpContent = new BatchWriteItemHighLevelHttpContent(this, node, Config.TableNamePrefix);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var documentResult = await DynamoDbLowLevelContext.ReadDocumentAsync(response, BatchWriteItemParsingOptions.Instance, cancellationToken).ConfigureAwait(false);

var attempt = 0;
Expand All @@ -35,7 +35,7 @@ internal async Task BatchWriteItemAsync(BuilderNode node, CancellationToken canc
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
using var unprocessedHttpContent = new BatchWriteItemHttpContent(new BatchWriteItemRequest{RequestItems = unprocessedItems}, null);

using var unprocessedResponse = await Api.SendAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
using var unprocessedResponse = await Api.SendAsync(unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
documentResult = await DynamoDbLowLevelContext.ReadDocumentAsync(unprocessedResponse, BatchWriteItemParsingOptions.Instance, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal async Task<List<TEntity>> BatchGetItemAsync<TEntity>(BuilderNode node,
{
using var httpContent = new BatchGetItemHighLevelHttpContent(this, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<BatchGetItemEntityResponse<TEntity>>(response, cancellationToken).ConfigureAwait(false);
List<TEntity>? items = null;
if (result.Responses?.Count > 0)
Expand All @@ -43,7 +43,7 @@ internal async Task<List<TEntity>> BatchGetItemAsync<TEntity>(BuilderNode node,
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
using var unprocessedHttpContent = new BatchGetItemHttpContent(new BatchGetItemRequest {RequestItems = result.UnprocessedKeys}, null);

using var unprocessedResponse = await Api.SendAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
using var unprocessedResponse = await Api.SendAsync(unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
result = await ReadAsync<BatchGetItemEntityResponse<TEntity>>(unprocessedResponse, cancellationToken).ConfigureAwait(false);

if (result.Responses?.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task DeleteItemAsync<TEntity>(object partitionKey, CancellationToke
{
using var httpContent = new DeleteItemByPkObjectHttpContent<TEntity>(this, partitionKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

await ReadAsync<object>(response, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -50,7 +50,7 @@ public async Task DeleteItemAsync<TEntity>(object partitionKey, object sortKey,
{
using var httpContent = new DeleteItemByPkAndSkObjectHttpContent<TEntity>(this, partitionKey, sortKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

await ReadAsync<object>(response, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -60,7 +60,7 @@ internal async Task<DeleteItemEntityResponse<TEntity>> DeleteItemResponseAsync<T
{
using var httpContent = new DeleteItemHighLevelHttpContent(this, classInfo, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

return await ReadAsync<DeleteItemEntityResponse<TEntity>>(response, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -70,7 +70,7 @@ internal async Task<DeleteItemEntityResponse<TEntity>> DeleteItemResponseAsync<T
{
using var httpContent = new DeleteItemHighLevelHttpContent(this, classInfo, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

var result = await ReadAsync<DeleteItemEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);
return result.Attributes;
Expand All @@ -80,7 +80,7 @@ internal async Task DeleteItemAsync(DdbClassInfo classInfo, BuilderNode node, Ca
{
using var httpContent = new DeleteItemHighLevelHttpContent(this, classInfo, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

await ReadAsync<object>(response, cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public partial class DynamoDbContext
{
using var httpContent = new GetItemByPkObjectHttpContent<TEntity>(this, partitionKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<GetItemEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

return result.Item;
Expand All @@ -55,7 +55,7 @@ public partial class DynamoDbContext
{
using var httpContent = new GetItemByPkAndSkObjectHttpContent<TEntity>(this, partitionKey, sortKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<GetItemEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

return result.Item;
Expand Down Expand Up @@ -98,7 +98,7 @@ public partial class DynamoDbContext
{
using var httpContent = new GetItemHighLevelHttpContent(this, classInfo, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<GetItemEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

return result.Item;
Expand All @@ -108,7 +108,7 @@ internal async Task<GetItemEntityResponse<TEntity>> GetItemResponseAsync<TEntity
{
using var httpContent = new GetItemHighLevelHttpContent(this, classInfo, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
return await ReadAsync<GetItemEntityResponse<TEntity>>(response, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal async Task<PutItemEntityResponse<TEntity>> PutItemResponseAsync<TEntity
{
using var httpContent = new PutItemHighLevelHttpContent(this, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

return await ReadAsync<PutItemEntityResponse<TEntity>>(response, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -41,7 +41,7 @@ internal async Task<PutItemEntityResponse<TEntity>> PutItemResponseAsync<TEntity
{
using var httpContent = new PutItemHighLevelHttpContent(this, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

var result = await ReadAsync<PutItemEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);
return result.Item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal async Task<IReadOnlyList<TEntity>> QueryListAsync<TEntity>(string? tabl
var contentNode = isFirst ? node : new PaginationTokenNode(result?.PaginationToken, node);
using var httpContent = new QueryHighLevelHttpContent(this, tableName, contentNode);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
result = await ReadAsync<QueryEntityResponseProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

if (items == null)
Expand All @@ -47,7 +47,7 @@ internal async Task<PagedResult<TEntity>> QueryPageAsync<TEntity>(string? tableN
{
using var httpContent = new QueryHighLevelHttpContent(this, tableName, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<QueryEntityResponseProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

return new PagedResult<TEntity>(result.Items, result.PaginationToken);
Expand All @@ -64,7 +64,7 @@ internal async IAsyncEnumerable<IReadOnlyList<TEntity>> QueryAsyncEnumerable<TEn
var contentNode = isFirst ? node : new PaginationTokenNode(result?.PaginationToken, node);
using var httpContent = new QueryHighLevelHttpContent(this, tableName, contentNode);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
result = await ReadAsync<QueryEntityResponseProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

yield return result.Items;
Expand All @@ -78,7 +78,7 @@ internal async Task<QueryEntityResponse<TEntity>> QueryAsync<TEntity>(string? ta
{
using var httpContent = new QueryHighLevelHttpContent(this, tableName, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
return await ReadAsync<QueryEntityResponse<TEntity>>(response, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/EfficientDynamoDb/DynamoDbContext/DynamoDbContext.Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal async Task<PagedResult<TEntity>> ScanPageAsync<TEntity>(string? tableNa
{
using var httpContent = new ScanHighLevelHttpContent(this, tableName, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<ScanEntityResponseProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

return new PagedResult<TEntity>(result.Items, result.PaginationToken);
Expand All @@ -38,7 +38,7 @@ internal async IAsyncEnumerable<IReadOnlyList<TEntity>> ScanAsyncEnumerable<TEnt
var contentNode = isFirst ? node : new PaginationTokenNode(result?.PaginationToken, node);
using var httpContent = new ScanHighLevelHttpContent(this, tableName, contentNode);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
result = await ReadAsync<ScanEntityResponseProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

yield return result.Items;
Expand All @@ -54,7 +54,7 @@ internal async Task<ScanEntityResponse<TEntity>> ScanAsync<TEntity>(string? tabl
{
using var httpContent = new ScanHighLevelHttpContent(this, tableName, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
return await ReadAsync<ScanEntityResponse<TEntity>>(response, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class DynamoDbContext
{
using var httpContent = new TransactGetItemsHighLevelHttpContent(this, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<TransactGetItemsEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);
var entities = new List<TEntity?>(result.Responses.Count);
foreach (var item in result.Responses)
Expand All @@ -32,7 +32,7 @@ internal async Task<TransactGetItemsEntityResponse<TEntity>> TransactGetItemsRes
{
using var httpContent = new TransactGetItemsHighLevelHttpContent(this, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
return await ReadAsync<TransactGetItemsEntityResponse<TEntity>>(response, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ internal async Task TransactWriteItemsAsync(BuilderNode node, CancellationToken
{
using var httpContent = new TransactWriteItemsHighLevelHttpContent(this, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
await ReadAsync<object>(response, cancellationToken).ConfigureAwait(false);
}

internal async Task<TransactWriteItemsEntityResponse> TransactWriteItemsResponseAsync(BuilderNode node, CancellationToken cancellationToken = default)
{
using var httpContent = new TransactWriteItemsHighLevelHttpContent(this, node);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
return await ReadAsync<TransactWriteItemsEntityResponse>(response, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
Loading