Week8-1_DynamoDB_Local_Sample
English translation
Verify that DynamoDB is installed locally
import boto3
def create_table(dynamodb=None):
if not dynamodb:
dynamodb = boto3.resource('dynamodb',
aws_access_key_id="anything",
aws_secret_access_key="anything",
region_name="us-west-2",
endpoint_url="http://localhost:8000")
table_name = 'Test'
table = dynamodb.create_table(TableName=table_name,
KeySchema=[
{'AttributeName': 'attr1','KeyType': 'HASH' # Partition key
},
{'AttributeName': 'attr2','KeyType': 'RANGE' # Sort key
}
],
AttributeDefinitions=[
{'AttributeName': 'attr1','AttributeType': 'N'},
{'AttributeName': 'attr2','AttributeType': 'S'}
],
ProvisionedThroughput={'ReadCapacityUnits': 10, 'WriteCapacityUnits': 10}
)
return table
if __name__ == '__main__':
sample_table = create_table()
print("Table status:", sample_table.table_status)Table status: ACTIVE