Cookie の設定を選択する

当社は、当社のサイトおよびサービスを提供するために必要な必須 Cookie および類似のツールを使用しています。当社は、パフォーマンス Cookie を使用して匿名の統計情報を収集することで、お客様が当社のサイトをどのように利用しているかを把握し、改善に役立てています。必須 Cookie は無効化できませんが、[カスタマイズ] または [拒否] をクリックしてパフォーマンス Cookie を拒否することはできます。

お客様が同意した場合、AWS および承認された第三者は、Cookie を使用して便利なサイト機能を提供したり、お客様の選択を記憶したり、関連する広告を含む関連コンテンツを表示したりします。すべての必須ではない Cookie を受け入れるか拒否するには、[受け入れる] または [拒否] をクリックしてください。より詳細な選択を行うには、[カスタマイズ] をクリックしてください。

AWS SDK を使用してウォームスループット設定で DynamoDB テーブルを作成する

フォーカスモード
AWS SDK を使用してウォームスループット設定で DynamoDB テーブルを作成する - Amazon DynamoDB

次のコード例は、ウォームスループットを有効にしたテーブルを作成する方法を示しています。

Java
SDK for Java 2.x

ウォームスループット設定で DynamoDB テーブルを作成します。

import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition; import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest; import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse; import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex; import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement; import software.amazon.awssdk.services.dynamodb.model.KeyType; import software.amazon.awssdk.services.dynamodb.model.Projection; import software.amazon.awssdk.services.dynamodb.model.ProjectionType; import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput; import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType; import software.amazon.awssdk.services.dynamodb.model.WarmThroughput; public static WarmThroughput buildWarmThroughput(final Long readUnitsPerSecond, final Long writeUnitsPerSecond) { return WarmThroughput.builder() .readUnitsPerSecond(readUnitsPerSecond) .writeUnitsPerSecond(writeUnitsPerSecond) .build(); } public static ProvisionedThroughput buildProvisionedThroughput(final Long readCapacityUnits, final Long writeCapacityUnits) { return ProvisionedThroughput.builder() .readCapacityUnits(readCapacityUnits) .writeCapacityUnits(writeCapacityUnits) .build(); } private static AttributeDefinition buildAttributeDefinition(final String attributeName, final ScalarAttributeType scalarAttributeType) { return AttributeDefinition.builder() .attributeName(attributeName) .attributeType(scalarAttributeType) .build(); } private static KeySchemaElement buildKeySchemaElement(final String attributeName, final KeyType keyType) { return KeySchemaElement.builder() .attributeName(attributeName) .keyType(keyType) .build(); } public static void createDynamoDBTable(DynamoDbClient ddb, String tableName, String partitionKey, String sortKey, String miscellaneousKeyAttribute, String nonKeyAttribute, Long tableReadCapacityUnits, Long tableWriteCapacityUnits, Long tableWarmReadUnitsPerSecond, Long tableWarmWriteUnitsPerSecond, String globalSecondaryIndexName, Long globalSecondaryIndexReadCapacityUnits, Long globalSecondaryIndexWriteCapacityUnits, Long globalSecondaryIndexWarmReadUnitsPerSecond, Long globalSecondaryIndexWarmWriteUnitsPerSecond) { // Define the table attributes final AttributeDefinition partitionKeyAttribute = buildAttributeDefinition(partitionKey, ScalarAttributeType.S); final AttributeDefinition sortKeyAttribute = buildAttributeDefinition(sortKey, ScalarAttributeType.S); final AttributeDefinition miscellaneousKeyAttributeDefinition = buildAttributeDefinition(miscellaneousKeyAttribute, ScalarAttributeType.N); final AttributeDefinition[] attributeDefinitions = {partitionKeyAttribute, sortKeyAttribute, miscellaneousKeyAttributeDefinition}; // Define the table key schema final KeySchemaElement partitionKeyElement = buildKeySchemaElement(partitionKey, KeyType.HASH); final KeySchemaElement sortKeyElement = buildKeySchemaElement(sortKey, KeyType.RANGE); final KeySchemaElement[] keySchema = {partitionKeyElement, sortKeyElement}; // Define the provisioned throughput for the table final ProvisionedThroughput provisionedThroughput = buildProvisionedThroughput(tableReadCapacityUnits, tableWriteCapacityUnits); // Define the Global Secondary Index (GSI) final KeySchemaElement globalSecondaryIndexPartitionKeyElement = buildKeySchemaElement(sortKey, KeyType.HASH); final KeySchemaElement globalSecondaryIndexSortKeyElement = buildKeySchemaElement(miscellaneousKeyAttribute, KeyType.RANGE); final KeySchemaElement[] gsiKeySchema = {globalSecondaryIndexPartitionKeyElement, globalSecondaryIndexSortKeyElement}; final Projection gsiProjection = Projection.builder() .projectionType(String.valueOf(ProjectionType.INCLUDE)) .nonKeyAttributes(nonKeyAttribute) .build(); final ProvisionedThroughput gsiProvisionedThroughput = buildProvisionedThroughput(globalSecondaryIndexReadCapacityUnits, globalSecondaryIndexWriteCapacityUnits); // Define the warm throughput for the Global Secondary Index (GSI) final WarmThroughput gsiWarmThroughput = buildWarmThroughput(globalSecondaryIndexWarmReadUnitsPerSecond, globalSecondaryIndexWarmWriteUnitsPerSecond); final GlobalSecondaryIndex globalSecondaryIndex = GlobalSecondaryIndex.builder() .indexName(globalSecondaryIndexName) .keySchema(gsiKeySchema) .projection(gsiProjection) .provisionedThroughput(gsiProvisionedThroughput) .warmThroughput(gsiWarmThroughput) .build(); // Define the warm throughput for the table final WarmThroughput tableWarmThroughput = buildWarmThroughput(tableWarmReadUnitsPerSecond, tableWarmWriteUnitsPerSecond); final CreateTableRequest request = CreateTableRequest.builder() .tableName(tableName) .attributeDefinitions(attributeDefinitions) .keySchema(keySchema) .provisionedThroughput(provisionedThroughput) .globalSecondaryIndexes(globalSecondaryIndex) .warmThroughput(tableWarmThroughput) .build(); CreateTableResponse response = ddb.createTable(request); System.out.println(response); }
  • API の詳細については、「AWS SDK for Java 2.x API リファレンス」の「CreateTable」を参照してください。

JavaScript
SDK for JavaScript (v3)
import { DynamoDBClient, CreateTableCommand } from "@aws-sdk/client-dynamodb"; async function createDynamoDBTableWithWarmThroughput( tableName, partitionKey, sortKey, miscKeyAttr, nonKeyAttr, tableProvisionedReadUnits, tableProvisionedWriteUnits, tableWarmReads, tableWarmWrites, indexName, indexProvisionedReadUnits, indexProvisionedWriteUnits, indexWarmReads, indexWarmWrites, region = "us-east-1" ) { try { const ddbClient = new DynamoDBClient({ region: region }); const command = new CreateTableCommand({ TableName: tableName, AttributeDefinitions: [ { AttributeName: partitionKey, AttributeType: "S" }, { AttributeName: sortKey, AttributeType: "S" }, { AttributeName: miscKeyAttr, AttributeType: "N" }, ], KeySchema: [ { AttributeName: partitionKey, KeyType: "HASH" }, { AttributeName: sortKey, KeyType: "RANGE" }, ], ProvisionedThroughput: { ReadCapacityUnits: tableProvisionedReadUnits, WriteCapacityUnits: tableProvisionedWriteUnits, }, WarmThroughput: { ReadUnitsPerSecond: tableWarmReads, WriteUnitsPerSecond: tableWarmWrites, }, GlobalSecondaryIndexes: [ { IndexName: indexName, KeySchema: [ { AttributeName: sortKey, KeyType: "HASH" }, { AttributeName: miscKeyAttr, KeyType: "RANGE" }, ], Projection: { ProjectionType: "INCLUDE", NonKeyAttributes: [nonKeyAttr], }, ProvisionedThroughput: { ReadCapacityUnits: indexProvisionedReadUnits, WriteCapacityUnits: indexProvisionedWriteUnits, }, WarmThroughput: { ReadUnitsPerSecond: indexWarmReads, WriteUnitsPerSecond: indexWarmWrites, }, }, ], }); const response = await ddbClient.send(command); console.log(response); } catch (error) { console.error(`Error creating table: ${error}`); throw error; } }
  • API の詳細については、「AWS SDK for JavaScript API リファレンス」の「CreateTable」を参照してください。

Python
SDK for Python (Boto3)
from boto3 import resource from botocore.exceptions import ClientError def create_dynamodb_table_warm_throughput(table_name, partition_key, sort_key, misc_key_attr, non_key_attr, table_provisioned_read_units, table_provisioned_write_units, table_warm_reads, table_warm_writes, gsi_name, gsi_provisioned_read_units, gsi_provisioned_write_units, gsi_warm_reads, gsi_warm_writes, region_name="us-east-1"): """ Creates a DynamoDB table with a warm throughput setting configured. :param table_name: The name of the table to be created. :param partition_key: The partition key for the table being created. :param sort_key: The sort key for the table being created. :param misc_key_attr: A miscellaneous key attribute for the table being created. :param non_key_attr: A non-key attribute for the table being created. :param table_provisioned_read_units: The newly created table's provisioned read capacity units. :param table_provisioned_write_units: The newly created table's provisioned write capacity units. :param table_warm_reads: The read units per second setting for the table's warm throughput. :param table_warm_writes: The write units per second setting for the table's warm throughput. :param gsi_name: The name of the Global Secondary Index (GSI) to be created on the table. :param gsi_provisioned_read_units: The configured Global Secondary Index (GSI) provisioned read capacity units. :param gsi_provisioned_write_units: The configured Global Secondary Index (GSI) provisioned write capacity units. :param gsi_warm_reads: The read units per second setting for the Global Secondary Index (GSI)'s warm throughput. :param gsi_warm_writes: The write units per second setting for the Global Secondary Index (GSI)'s warm throughput. :param region_name: The AWS Region name to target. defaults to us-east-1 """ try: ddb = resource('dynamodb', region_name) # Define the table attributes attribute_definitions = [ { "AttributeName": partition_key, "AttributeType": "S" }, { "AttributeName": sort_key, "AttributeType": "S" }, { "AttributeName": misc_key_attr, "AttributeType": "N" } ] # Define the table key schema key_schema = [ { "AttributeName": partition_key, "KeyType": "HASH" }, { "AttributeName": sort_key, "KeyType": "RANGE" } ] # Define the provisioned throughput for the table provisioned_throughput = { "ReadCapacityUnits": table_provisioned_read_units, "WriteCapacityUnits": table_provisioned_write_units } # Define the global secondary index gsi_key_schema = [ { "AttributeName": sort_key, "KeyType": "HASH" }, { "AttributeName": misc_key_attr, "KeyType": "RANGE" } ] gsi_projection = { "ProjectionType": "INCLUDE", "NonKeyAttributes": [non_key_attr] } gsi_provisioned_throughput = { "ReadCapacityUnits": gsi_provisioned_read_units, "WriteCapacityUnits": gsi_provisioned_write_units } gsi_warm_throughput = { "ReadUnitsPerSecond": gsi_warm_reads, "WriteUnitsPerSecond": gsi_warm_writes } global_secondary_indexes = [ { "IndexName": gsi_name, "KeySchema": gsi_key_schema, "Projection": gsi_projection, "ProvisionedThroughput": gsi_provisioned_throughput, "WarmThroughput": gsi_warm_throughput } ] # Define the warm throughput for the table warm_throughput = { "ReadUnitsPerSecond": table_warm_reads, "WriteUnitsPerSecond": table_warm_writes } # Create the DynamoDB client and create the table response = ddb.create_table( TableName=table_name, AttributeDefinitions=attribute_definitions, KeySchema=key_schema, ProvisionedThroughput=provisioned_throughput, GlobalSecondaryIndexes=global_secondary_indexes, WarmThroughput=warm_throughput ) print(response) except ClientError as e: print(f"Error creating table: {e}") raise e
  • API の詳細については、『AWS SDK for Python (Boto3) API リファレンス』の「CreateTable」を参照してください。

SDK for Java 2.x

ウォームスループット設定で DynamoDB テーブルを作成します。

import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition; import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest; import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse; import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex; import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement; import software.amazon.awssdk.services.dynamodb.model.KeyType; import software.amazon.awssdk.services.dynamodb.model.Projection; import software.amazon.awssdk.services.dynamodb.model.ProjectionType; import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput; import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType; import software.amazon.awssdk.services.dynamodb.model.WarmThroughput; public static WarmThroughput buildWarmThroughput(final Long readUnitsPerSecond, final Long writeUnitsPerSecond) { return WarmThroughput.builder() .readUnitsPerSecond(readUnitsPerSecond) .writeUnitsPerSecond(writeUnitsPerSecond) .build(); } public static ProvisionedThroughput buildProvisionedThroughput(final Long readCapacityUnits, final Long writeCapacityUnits) { return ProvisionedThroughput.builder() .readCapacityUnits(readCapacityUnits) .writeCapacityUnits(writeCapacityUnits) .build(); } private static AttributeDefinition buildAttributeDefinition(final String attributeName, final ScalarAttributeType scalarAttributeType) { return AttributeDefinition.builder() .attributeName(attributeName) .attributeType(scalarAttributeType) .build(); } private static KeySchemaElement buildKeySchemaElement(final String attributeName, final KeyType keyType) { return KeySchemaElement.builder() .attributeName(attributeName) .keyType(keyType) .build(); } public static void createDynamoDBTable(DynamoDbClient ddb, String tableName, String partitionKey, String sortKey, String miscellaneousKeyAttribute, String nonKeyAttribute, Long tableReadCapacityUnits, Long tableWriteCapacityUnits, Long tableWarmReadUnitsPerSecond, Long tableWarmWriteUnitsPerSecond, String globalSecondaryIndexName, Long globalSecondaryIndexReadCapacityUnits, Long globalSecondaryIndexWriteCapacityUnits, Long globalSecondaryIndexWarmReadUnitsPerSecond, Long globalSecondaryIndexWarmWriteUnitsPerSecond) { // Define the table attributes final AttributeDefinition partitionKeyAttribute = buildAttributeDefinition(partitionKey, ScalarAttributeType.S); final AttributeDefinition sortKeyAttribute = buildAttributeDefinition(sortKey, ScalarAttributeType.S); final AttributeDefinition miscellaneousKeyAttributeDefinition = buildAttributeDefinition(miscellaneousKeyAttribute, ScalarAttributeType.N); final AttributeDefinition[] attributeDefinitions = {partitionKeyAttribute, sortKeyAttribute, miscellaneousKeyAttributeDefinition}; // Define the table key schema final KeySchemaElement partitionKeyElement = buildKeySchemaElement(partitionKey, KeyType.HASH); final KeySchemaElement sortKeyElement = buildKeySchemaElement(sortKey, KeyType.RANGE); final KeySchemaElement[] keySchema = {partitionKeyElement, sortKeyElement}; // Define the provisioned throughput for the table final ProvisionedThroughput provisionedThroughput = buildProvisionedThroughput(tableReadCapacityUnits, tableWriteCapacityUnits); // Define the Global Secondary Index (GSI) final KeySchemaElement globalSecondaryIndexPartitionKeyElement = buildKeySchemaElement(sortKey, KeyType.HASH); final KeySchemaElement globalSecondaryIndexSortKeyElement = buildKeySchemaElement(miscellaneousKeyAttribute, KeyType.RANGE); final KeySchemaElement[] gsiKeySchema = {globalSecondaryIndexPartitionKeyElement, globalSecondaryIndexSortKeyElement}; final Projection gsiProjection = Projection.builder() .projectionType(String.valueOf(ProjectionType.INCLUDE)) .nonKeyAttributes(nonKeyAttribute) .build(); final ProvisionedThroughput gsiProvisionedThroughput = buildProvisionedThroughput(globalSecondaryIndexReadCapacityUnits, globalSecondaryIndexWriteCapacityUnits); // Define the warm throughput for the Global Secondary Index (GSI) final WarmThroughput gsiWarmThroughput = buildWarmThroughput(globalSecondaryIndexWarmReadUnitsPerSecond, globalSecondaryIndexWarmWriteUnitsPerSecond); final GlobalSecondaryIndex globalSecondaryIndex = GlobalSecondaryIndex.builder() .indexName(globalSecondaryIndexName) .keySchema(gsiKeySchema) .projection(gsiProjection) .provisionedThroughput(gsiProvisionedThroughput) .warmThroughput(gsiWarmThroughput) .build(); // Define the warm throughput for the table final WarmThroughput tableWarmThroughput = buildWarmThroughput(tableWarmReadUnitsPerSecond, tableWarmWriteUnitsPerSecond); final CreateTableRequest request = CreateTableRequest.builder() .tableName(tableName) .attributeDefinitions(attributeDefinitions) .keySchema(keySchema) .provisionedThroughput(provisionedThroughput) .globalSecondaryIndexes(globalSecondaryIndex) .warmThroughput(tableWarmThroughput) .build(); CreateTableResponse response = ddb.createTable(request); System.out.println(response); }
  • API の詳細については、「AWS SDK for Java 2.x API リファレンス」の「CreateTable」を参照してください。

AWS SDK デベロッパーガイドとコード例の詳細なリストについては、「AWS SDK で DynamoDB を使用する」を参照してください。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。

プライバシーサイト規約Cookie の設定
© 2025, Amazon Web Services, Inc. or its affiliates.All rights reserved.