![](/img/trans.png)
[英]botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden while using local mode in AWS SageMaker
[英]Error while creating dynamodb table using boto3 ("botocore.exceptions.ClientError")
我正在尝试使用 boto3 创建一个 dynamodb 表。 但我收到以下错误:
“botocore.exceptions.ClientError:调用 CreateTable 操作时发生错误(ValidationException):无效的 KeySchema:第一个 KeySchemaElement 不是 HASH 键类型”
更多信息:我的帐户中没有任何全局表。
我试过的代码:
import boto3
client = boto3.client('dynamodb')
response = client.create_table(
AttributeDefinitions=[
{
'AttributeName': 'student_id',
'AttributeType': 'N'
},
{
'AttributeName': 'student_name',
'AttributeType': 'S'
},
{
'AttributeName': 'course_id',
'AttributeType': 'S'
}
],
TableName='students',
KeySchema=[
{
'AttributeName': 'student_name',
'KeyType': 'HASH'
},
{
'AttributeName': 'student_id',
'KeyType': 'RANGE'
},
],
LocalSecondaryIndexes=[
{
'IndexName': 'course_id',
'KeySchema': [
{
'AttributeName': 'course_id',
'KeyType': 'RANGE'
}
],
'Projection': {
'ProjectionType': 'ALL'
}
},
],
BillingMode='PAY_PER_REQUEST',
)
您也应该为 LSI 明确指定 HASH 密钥。
import boto3
client = boto3.client('dynamodb')
response = client.create_table(
AttributeDefinitions=[
{
'AttributeName': 'student_id',
'AttributeType': 'N'
},
{
'AttributeName': 'student_name',
'AttributeType': 'S'
},
{
'AttributeName': 'course_id',
'AttributeType': 'S'
}
],
TableName='students',
KeySchema=[
{
'AttributeName': 'student_name',
'KeyType': 'HASH'
},
{
'AttributeName': 'student_id',
'KeyType': 'RANGE'
},
],
LocalSecondaryIndexes=[
{
'IndexName': 'course_id',
'KeySchema': [
{
'AttributeName': 'student_name',
'KeyType': 'HASH'
},
{
'AttributeName': 'course_id',
'KeyType': 'RANGE'
}
],
'Projection': {
'ProjectionType': 'ALL'
}
},
],
BillingMode='PAY_PER_REQUEST',
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.