쿠키 기본 설정 선택

당사는 사이트와 서비스를 제공하는 데 필요한 필수 쿠키 및 유사한 도구를 사용합니다. 고객이 사이트를 어떻게 사용하는지 파악하고 개선할 수 있도록 성능 쿠키를 사용해 익명의 통계를 수집합니다. 필수 쿠키는 비활성화할 수 없지만 '사용자 지정' 또는 ‘거부’를 클릭하여 성능 쿠키를 거부할 수 있습니다.

사용자가 동의하는 경우 AWS와 승인된 제3자도 쿠키를 사용하여 유용한 사이트 기능을 제공하고, 사용자의 기본 설정을 기억하고, 관련 광고를 비롯한 관련 콘텐츠를 표시합니다. 필수가 아닌 모든 쿠키를 수락하거나 거부하려면 ‘수락’ 또는 ‘거부’를 클릭하세요. 더 자세한 내용을 선택하려면 ‘사용자 정의’를 클릭하세요.

웜 처리량이 더 높은 새 DynamoDB 테이블 만들기

포커스 모드
웜 처리량이 더 높은 새 DynamoDB 테이블 만들기 - Amazon DynamoDB

아래 단계에 따라 DynamoDB 테이블을 만들 때 웜 처리량 값을 조정할 수 있습니다. 이러한 단계는 글로벌 테이블 또는 보조 인덱스를 만들 때도 적용됩니다.

DynamoDB 테이블을 만들고 콘솔을 통해 웜 처리량 값을 조정하려면:

  1. AWS Management Console에 로그인하고 https://console.aws.amazon.com/dynamodb/에서 DynamoDB 콘솔을 엽니다.

  2. 규칙 생성을 선택합니다.

  3. 테이블 이름, 파티션 키정렬 키(선택 사항)를 선택합니다.

  4. 테이블 설정에서 설정 사용자 지정을 선택합니다.

  5. 웜 처리량 필드에서 웜 처리량 증가를 선택합니다.

  6. 초당 읽기 단위초당 쓰기 단위를 조정합니다. 이 두 설정은 테이블이 즉시 처리할 수 있는 최대 처리량을 정의합니다.

  7. 나머지 테이블 세부 정보를 계속 추가한 다음 테이블 생성을 선택합니다.

DynamoDB 테이블을 만들고 콘솔을 통해 웜 처리량 값을 조정하려면:

  1. AWS Management Console에 로그인하고 https://console.aws.amazon.com/dynamodb/에서 DynamoDB 콘솔을 엽니다.

  2. 규칙 생성을 선택합니다.

  3. 테이블 이름, 파티션 키정렬 키(선택 사항)를 선택합니다.

  4. 테이블 설정에서 설정 사용자 지정을 선택합니다.

  5. 웜 처리량 필드에서 웜 처리량 증가를 선택합니다.

  6. 초당 읽기 단위초당 쓰기 단위를 조정합니다. 이 두 설정은 테이블이 즉시 처리할 수 있는 최대 처리량을 정의합니다.

  7. 나머지 테이블 세부 정보를 계속 추가한 다음 테이블 생성을 선택합니다.

다음 AWS CLI 예제에서는 사용자 지정 웜 처리량 값을 사용하여 DynamoDB 테이블을 만드는 방법을 보여줍니다.

  1. create-table 작업을 실행하여 다음 DynamoDB 테이블을 만듭니다.

    aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S \ AttributeName=GameTitle,AttributeType=S \ AttributeName=TopScore,AttributeType=N \ --key-schema AttributeName=UserId,KeyType=HASH \ AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=20,WriteCapacityUnits=10 \ --global-secondary-indexes \ "[ { \"IndexName\": \"GameTitleIndex\", \"KeySchema\": [{\"AttributeName\":\"GameTitle\",\"KeyType\":\"HASH\"}, {\"AttributeName\":\"TopScore\",\"KeyType\":\"RANGE\"}], \"Projection\":{ \"ProjectionType\":\"INCLUDE\", \"NonKeyAttributes\":[\"UserId\"] }, \"ProvisionedThroughput\": { \"ReadCapacityUnits\": 50, \"WriteCapacityUnits\": 25 },\"WarmThroughput\": { \"ReadUnitsPerSecond\": 1987, \"WriteUnitsPerSecond\": 543 } } ]" \ --warm-throughput ReadUnitsPerSecond=12345,WriteUnitsPerSecond=4567 \ --region us-east-1
  2. 아래와 비슷한 응답을 받게 됩니다. WarmThroughput 설정은 ReadUnitsPerSecondWriteUnitsPerSecond로 표시됩니다. Status는 웜 처리량 값이 업데이트될 때는 UPDATING, 새 웜 처리량 값이 설정되었을 때는 ACTIVE가 됩니다.

    { "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "TopScore", "AttributeType": "N" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": 1730241788.779, "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 20, "WriteCapacityUnits": 10 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores", "TableId": "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "GlobalSecondaryIndexes": [ { "IndexName": "GameTitleIndex", "KeySchema": [ { "AttributeName": "GameTitle", "KeyType": "HASH" }, { "AttributeName": "TopScore", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "INCLUDE", "NonKeyAttributes": [ "UserId" ] }, "IndexStatus": "CREATING", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 50, "WriteCapacityUnits": 25 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores/index/GameTitleIndex", "WarmThroughput": { "ReadUnitsPerSecond": 1987, "WriteUnitsPerSecond": 543, "Status": "UPDATING" } } ], "DeletionProtectionEnabled": false, "WarmThroughput": { "ReadUnitsPerSecond": 12345, "WriteUnitsPerSecond": 4567, "Status": "UPDATING" } } }

다음 AWS CLI 예제에서는 사용자 지정 웜 처리량 값을 사용하여 DynamoDB 테이블을 만드는 방법을 보여줍니다.

  1. create-table 작업을 실행하여 다음 DynamoDB 테이블을 만듭니다.

    aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S \ AttributeName=GameTitle,AttributeType=S \ AttributeName=TopScore,AttributeType=N \ --key-schema AttributeName=UserId,KeyType=HASH \ AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=20,WriteCapacityUnits=10 \ --global-secondary-indexes \ "[ { \"IndexName\": \"GameTitleIndex\", \"KeySchema\": [{\"AttributeName\":\"GameTitle\",\"KeyType\":\"HASH\"}, {\"AttributeName\":\"TopScore\",\"KeyType\":\"RANGE\"}], \"Projection\":{ \"ProjectionType\":\"INCLUDE\", \"NonKeyAttributes\":[\"UserId\"] }, \"ProvisionedThroughput\": { \"ReadCapacityUnits\": 50, \"WriteCapacityUnits\": 25 },\"WarmThroughput\": { \"ReadUnitsPerSecond\": 1987, \"WriteUnitsPerSecond\": 543 } } ]" \ --warm-throughput ReadUnitsPerSecond=12345,WriteUnitsPerSecond=4567 \ --region us-east-1
  2. 아래와 비슷한 응답을 받게 됩니다. WarmThroughput 설정은 ReadUnitsPerSecondWriteUnitsPerSecond로 표시됩니다. Status는 웜 처리량 값이 업데이트될 때는 UPDATING, 새 웜 처리량 값이 설정되었을 때는 ACTIVE가 됩니다.

    { "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "TopScore", "AttributeType": "N" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": 1730241788.779, "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 20, "WriteCapacityUnits": 10 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores", "TableId": "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "GlobalSecondaryIndexes": [ { "IndexName": "GameTitleIndex", "KeySchema": [ { "AttributeName": "GameTitle", "KeyType": "HASH" }, { "AttributeName": "TopScore", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "INCLUDE", "NonKeyAttributes": [ "UserId" ] }, "IndexStatus": "CREATING", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 50, "WriteCapacityUnits": 25 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores/index/GameTitleIndex", "WarmThroughput": { "ReadUnitsPerSecond": 1987, "WriteUnitsPerSecond": 543, "Status": "UPDATING" } } ], "DeletionProtectionEnabled": false, "WarmThroughput": { "ReadUnitsPerSecond": 12345, "WriteUnitsPerSecond": 4567, "Status": "UPDATING" } } }

다음 SDK 예제에서는 사용자 지정 웜 처리량 값을 사용하여 DynamoDB 테이블을 생성하는 방법을 보여줍니다.

Java
import software.amazon.awscdk.services.dynamodb.ProjectionType; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse; import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest; import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement; import software.amazon.awssdk.services.dynamodb.model.KeyType; import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput; import software.amazon.awssdk.services.dynamodb.model.Projection; import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex; import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition; 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(); } 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 = ProvisionedThroughput.builder() .readCapacityUnits(tableReadCapacityUnits) .writeCapacityUnits(tableWriteCapacityUnits) .build(); // 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 = ProvisionedThroughput.builder() .readCapacityUnits(globalSecondaryIndexReadCapacityUnits) .writeCapacityUnits(globalSecondaryIndexWriteCapacityUnits) .build(); // 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); }
Python
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
Javascript
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; } }

다음 SDK 예제에서는 사용자 지정 웜 처리량 값을 사용하여 DynamoDB 테이블을 생성하는 방법을 보여줍니다.

Java
import software.amazon.awscdk.services.dynamodb.ProjectionType; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse; import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest; import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement; import software.amazon.awssdk.services.dynamodb.model.KeyType; import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput; import software.amazon.awssdk.services.dynamodb.model.Projection; import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex; import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition; 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(); } 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 = ProvisionedThroughput.builder() .readCapacityUnits(tableReadCapacityUnits) .writeCapacityUnits(tableWriteCapacityUnits) .build(); // 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 = ProvisionedThroughput.builder() .readCapacityUnits(globalSecondaryIndexReadCapacityUnits) .writeCapacityUnits(globalSecondaryIndexWriteCapacityUnits) .build(); // 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); }
Python
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
Javascript
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; } }
import software.amazon.awscdk.services.dynamodb.ProjectionType; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse; import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest; import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement; import software.amazon.awssdk.services.dynamodb.model.KeyType; import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput; import software.amazon.awssdk.services.dynamodb.model.Projection; import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex; import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition; 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(); } 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 = ProvisionedThroughput.builder() .readCapacityUnits(tableReadCapacityUnits) .writeCapacityUnits(tableWriteCapacityUnits) .build(); // 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 = ProvisionedThroughput.builder() .readCapacityUnits(globalSecondaryIndexReadCapacityUnits) .writeCapacityUnits(globalSecondaryIndexWriteCapacityUnits) .build(); // 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); }
프라이버시사이트 이용 약관쿠키 기본 설정
© 2025, Amazon Web Services, Inc. 또는 계열사. All rights reserved.