Skip to content

.NET v3: Default to on-demand tables in .NET DynamoDB examples. #7263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 40 additions & 0 deletions dotnetv3/DotNetV3Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "S3ObjectLockTests", "S3\sce
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConverseToolScenario", "Bedrock-runtime\Scenarios\ConverseToolScenario\ConverseToolScenario.csproj", "{83ED7BBE-5C9A-47AC-805B-351270069570}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DynamoDB_Actions", "DynamoDB_Actions", "{72466F30-810F-4963-B748-5154A6C49926}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamoDB_Actions", "dynamodb\scenarios\DynamoDB_Basics\DynamoDB_Actions\DynamoDB_Actions.csproj", "{B8843CE1-23AF-4E54-A916-C3FD94B4FF9A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AmazonNova", "AmazonNova", "{9FB5136B-F426-454C-B32D-855E07DBC0FE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AmazonNovaText", "AmazonNovaText", "{6EA5F10D-C016-4AB0-B551-099DBFD74F95}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConverseStream", "Bedrock-runtime\Models\AmazonNova\AmazonNovaText\ConverseStream\ConverseStream.csproj", "{C0AC14E2-54E9-426E-8A4A-7B64946A4715}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Converse", "Bedrock-runtime\Models\AmazonNova\AmazonNovaText\Converse\Converse.csproj", "{FD901D0E-B970-42A3-B6E2-219BDA882F19}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AmazonNovaCanvas", "AmazonNovaCanvas", "{CDA2FA21-36E1-4847-A5A8-AF921C4BBBD7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InvokeModel", "Bedrock-runtime\Models\AmazonNova\AmazonNovaCanvas\InvokeModel\InvokeModel.csproj", "{1D2CF12A-F46E-4293-ABB3-2FD70D84328F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1921,6 +1937,22 @@ Global
{83ED7BBE-5C9A-47AC-805B-351270069570}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83ED7BBE-5C9A-47AC-805B-351270069570}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83ED7BBE-5C9A-47AC-805B-351270069570}.Release|Any CPU.Build.0 = Release|Any CPU
{B8843CE1-23AF-4E54-A916-C3FD94B4FF9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8843CE1-23AF-4E54-A916-C3FD94B4FF9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8843CE1-23AF-4E54-A916-C3FD94B4FF9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8843CE1-23AF-4E54-A916-C3FD94B4FF9A}.Release|Any CPU.Build.0 = Release|Any CPU
{C0AC14E2-54E9-426E-8A4A-7B64946A4715}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0AC14E2-54E9-426E-8A4A-7B64946A4715}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0AC14E2-54E9-426E-8A4A-7B64946A4715}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0AC14E2-54E9-426E-8A4A-7B64946A4715}.Release|Any CPU.Build.0 = Release|Any CPU
{FD901D0E-B970-42A3-B6E2-219BDA882F19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD901D0E-B970-42A3-B6E2-219BDA882F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD901D0E-B970-42A3-B6E2-219BDA882F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD901D0E-B970-42A3-B6E2-219BDA882F19}.Release|Any CPU.Build.0 = Release|Any CPU
{1D2CF12A-F46E-4293-ABB3-2FD70D84328F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D2CF12A-F46E-4293-ABB3-2FD70D84328F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D2CF12A-F46E-4293-ABB3-2FD70D84328F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D2CF12A-F46E-4293-ABB3-2FD70D84328F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2303,6 +2335,14 @@ Global
{93588ED1-A248-4F6C-85A4-27E9E65D8AC7} = {7EC94891-9A5F-47EF-9C97-8A280754525C}
{BCCFBED0-E800-46C5-975B-7D404486F00F} = {7EC94891-9A5F-47EF-9C97-8A280754525C}
{83ED7BBE-5C9A-47AC-805B-351270069570} = {BA23BB28-EC63-4330-8CA7-DEB1B6489580}
{72466F30-810F-4963-B748-5154A6C49926} = {3F9C4507-5BD7-4AA5-9EE0-538DE08FAF43}
{B8843CE1-23AF-4E54-A916-C3FD94B4FF9A} = {72466F30-810F-4963-B748-5154A6C49926}
{9FB5136B-F426-454C-B32D-855E07DBC0FE} = {6520EB28-F7B4-4581-B3D8-A06E9303B16B}
{6EA5F10D-C016-4AB0-B551-099DBFD74F95} = {9FB5136B-F426-454C-B32D-855E07DBC0FE}
{C0AC14E2-54E9-426E-8A4A-7B64946A4715} = {6EA5F10D-C016-4AB0-B551-099DBFD74F95}
{FD901D0E-B970-42A3-B6E2-219BDA882F19} = {6EA5F10D-C016-4AB0-B551-099DBFD74F95}
{CDA2FA21-36E1-4847-A5A8-AF921C4BBBD7} = {9FB5136B-F426-454C-B32D-855E07DBC0FE}
{1D2CF12A-F46E-4293-ABB3-2FD70D84328F} = {CDA2FA21-36E1-4847-A5A8-AF921C4BBBD7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08502818-E8E1-4A91-A51C-4C8C8D4FF9CA}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,22 @@ public static async Task<DescribeTableResponse> CreateTableProductCatalog(IAmazo
{
TableName = tableName,
AttributeDefinitions = new List<AttributeDefinition>()
{
new AttributeDefinition
{
AttributeName = "Id",
AttributeType = ScalarAttributeType.N,
},
},
{
new AttributeDefinition
{
AttributeName = "Id",
AttributeType = ScalarAttributeType.N,
},
},
KeySchema = new List<KeySchemaElement>()
{
new KeySchemaElement
{
AttributeName = "Id",
KeyType = KeyType.HASH,
},
},
ProvisionedThroughput = new ProvisionedThroughput
{
new KeySchemaElement
{
ReadCapacityUnits = 10,
WriteCapacityUnits = 5,
AttributeName = "Id",
KeyType = KeyType.HASH,
},
},
BillingMode = BillingMode.PAY_PER_REQUEST,
});

var result = await WaitTillTableCreated(client, tableName, response);
Expand All @@ -112,26 +108,22 @@ public static async Task<DescribeTableResponse> CreateTableForum(IAmazonDynamoDB
{
TableName = tableName,
AttributeDefinitions = new List<AttributeDefinition>()
{
new AttributeDefinition
{
AttributeName = "Name",
AttributeType = ScalarAttributeType.S,
},
},
{
new AttributeDefinition
{
AttributeName = "Name",
AttributeType = ScalarAttributeType.S,
},
},
KeySchema = new List<KeySchemaElement>()
{
new KeySchemaElement
{
AttributeName = "Name",
KeyType = KeyType.HASH,
},
},
ProvisionedThroughput = new ProvisionedThroughput
{
new KeySchemaElement
{
ReadCapacityUnits = 10,
WriteCapacityUnits = 5,
AttributeName = "Name",
KeyType = KeyType.HASH,
},
},
BillingMode = BillingMode.PAY_PER_REQUEST,
});

var result = await WaitTillTableCreated(client, tableName, response);
Expand All @@ -154,36 +146,32 @@ public static async Task<DescribeTableResponse> CreateTableThread(IAmazonDynamoD
{
TableName = tableName,
AttributeDefinitions = new List<AttributeDefinition>()
{
new AttributeDefinition
{
AttributeName = "ForumName", // Hash attribute.
AttributeType = ScalarAttributeType.S,
},
new AttributeDefinition
{
AttributeName = "Subject",
AttributeType = ScalarAttributeType.S,
},
},
{
new AttributeDefinition
{
AttributeName = "ForumName", // Hash attribute.
AttributeType = ScalarAttributeType.S,
},
new AttributeDefinition
{
AttributeName = "Subject",
AttributeType = ScalarAttributeType.S,
},
},
KeySchema = new List<KeySchemaElement>()
{
new KeySchemaElement
{
AttributeName = "ForumName", // Hash attribute
KeyType = KeyType.HASH,
},
new KeySchemaElement
{
AttributeName = "Subject", // Range attribute
KeyType = KeyType.RANGE,
},
},
ProvisionedThroughput = new ProvisionedThroughput
{
new KeySchemaElement
{
AttributeName = "ForumName", // Hash attribute
KeyType = KeyType.HASH,
},
new KeySchemaElement
{
ReadCapacityUnits = 10,
WriteCapacityUnits = 5,
AttributeName = "Subject", // Range attribute
KeyType = KeyType.RANGE,
},
},
BillingMode = BillingMode.PAY_PER_REQUEST,
});

var result = await WaitTillTableCreated(client, tableName, response);
Expand Down Expand Up @@ -256,11 +244,7 @@ public static async Task<DescribeTableResponse> CreateTableReply(IAmazonDynamoDB
},
},
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 10,
WriteCapacityUnits = 5,
},
BillingMode = BillingMode.PAY_PER_REQUEST,
});

var result = await WaitTillTableCreated(client, tableName, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.Core" Version="3.7.2.10" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.0.59" />
<PackageReference Include="AWSSDK.Core" Version="3.7.402.7" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.405.28" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
22 changes: 11 additions & 11 deletions dotnetv3/dynamodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ Code excerpts that show you how to call individual service functions.

- [BatchExecuteStatement](scenarios/PartiQL_Batch_Scenario/PartiQL_Batch_Scenario/PartiQLBatchMethods.cs#L10)
- [BatchGetItem](low-level-api/LowLevelBatchGet/LowLevelBatchGet.cs#L4)
- [BatchWriteItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L202)
- [BatchWriteItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L198)
- [CreateTable](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L14)
- [DeleteItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L262)
- [DeleteTable](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L391)
- [DescribeTable](low-level-api/LowLevelTableExample/LowLevelTableExample.cs#L126)
- [DeleteItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L258)
- [DeleteTable](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L387)
- [DescribeTable](low-level-api/LowLevelTableExample/LowLevelTableExample.cs#L120)
- [ExecuteStatement](scenarios/PartiQL_Basics_Scenario/PartiQL_Basics_Scenario/PartiQLMethods.cs#L163)
- [GetItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L171)
- [ListTables](low-level-api/LowLevelTableExample/LowLevelTableExample.cs#L102)
- [PutItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L89)
- [Query](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L297)
- [Scan](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L350)
- [UpdateItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L119)
- [GetItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L167)
- [ListTables](low-level-api/LowLevelTableExample/LowLevelTableExample.cs#L96)
- [PutItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L85)
- [Query](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L293)
- [Scan](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L346)
- [UpdateItem](scenarios/DynamoDB_Basics/DynamoDB_Actions/DynamoDbMethods.cs#L115)

### Scenarios

Expand Down Expand Up @@ -240,4 +240,4 @@ in the `dotnetv3` folder.

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,12 @@ private static async Task CreateExampleTable()
KeyType = KeyType.RANGE //Sort key
}
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 6
},
TableName = ExampleTableName
TableName = ExampleTableName,
BillingMode = BillingMode.PAY_PER_REQUEST,
});

var tableDescription = response.TableDescription;
Console.WriteLine($"{tableDescription.TableName}: {tableDescription.TableStatus} \t " +
$"ReadsPerSec: {tableDescription.ProvisionedThroughput.ReadCapacityUnits} \t " +
$"WritesPerSec: {tableDescription.ProvisionedThroughput.WriteCapacityUnits}");
Console.WriteLine($"{tableDescription.TableName}: {tableDescription.TableStatus}");

Console.WriteLine($"{ExampleTableName} - {tableDescription.TableStatus}");

Expand Down Expand Up @@ -136,21 +130,19 @@ private static async Task GetTableInformation()
var table = response.Table;
Console.WriteLine($"Name: {table.TableName}");
Console.WriteLine($"# of items: {table.ItemCount}");
Console.WriteLine($"Provision Throughput (reads/sec): " +
$"{table.ProvisionedThroughput.ReadCapacityUnits}");
Console.WriteLine($"Provision Throughput (writes/sec): " +
$"{table.ProvisionedThroughput.WriteCapacityUnits}");

}
// snippet-end:[dynamodb.dotnetv3.DescribeTableExample]

// snippet-start:[dynamodb.dotnetv3.UpdateExampleTable]
private static async Task UpdateExampleTable()
{
Console.WriteLine("\n*** Updating table ***");
Console.WriteLine("\n*** Updating table billing mode ***");

await Client.UpdateTableAsync(new UpdateTableRequest
{
TableName = ExampleTableName,
BillingMode = BillingMode.PROVISIONED,
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public static async Task<bool> CreateMovieTableAsync(AmazonDynamoDBClient client
KeyType = KeyType.RANGE,
},
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 5,
},
BillingMode = BillingMode.PAY_PER_REQUEST,
});

// Wait until the table is ACTIVE and then report success.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public static async Task<bool> CreateMovieTableAsync(string tableName)
KeyType = KeyType.RANGE,
},
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 5,
},
BillingMode = BillingMode.PAY_PER_REQUEST,
});

// Wait until the table is ACTIVE and then report success.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Separator for the console display.
var SepBar = new string('-', 80);
const string tableName = "movie_table";
const string movieFileName = "moviedata.json";
const string movieFileName = @"..\..\..\..\..\..\..\..\resources\sample_files\movies.json";

var client = new AmazonDynamoDBClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public static async Task<bool> CreateMovieTableAsync(string tableName)
KeyType = KeyType.RANGE,
},
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 5,
},
BillingMode = BillingMode.PAY_PER_REQUEST,
});

// Wait until the table is ACTIVE and then report success.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

// Separator for the console display.
var SepBar = new string('-', 80);
const string tableName = "movie_table";
const string movieFileName = "moviedata.json";
const string tableName = "movie_table6";
const string movieFileName = @"..\..\..\..\..\..\..\..\resources\sample_files\movies.json";

DisplayInstructions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static async Task<bool> GetBatch(
int year1,
int year2)
{
var getBatch = $"SELECT FROM {tableName} WHERE title = ? AND year = ?";
var getBatch = $"SELECT * FROM {tableName} WHERE title = ? AND year = ?";
var statements = new List<BatchStatementRequest>
{
new BatchStatementRequest
Expand Down
Loading