Amazon DynamoDB table w/ Elastic Beanstalk 没有设置正确的参数
Amazon DynamoDB table w/ Elastic Beanstalk not setting up correct parameters
我有一个来自 Amazon 的示例 Dynamodb
项目,当上传到 Elastic Beanstalk
环境的实例时,会生成一个 Dynamodb
table。但是,在生成 table 后缺少一些参数。
这是 Elastic Beanstalk
实例的代码:
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.geo.util;
import com.amazonaws.geo.GeoDataManagerConfiguration;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex;
import com.amazonaws.services.dynamodbv2.model.Projection;
import com.amazonaws.services.dynamodbv2.model.ProjectionType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType;
/**
* Utility class.
* */
public class GeoTableUtil {
/**
* <p>
* Construct a create table request object based on GeoDataManagerConfiguration. The users can update any aspect of
* the request and call it.
* </p>
* Example:
*
* <pre>
* AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
* Region usWest2 = Region.getRegion(Regions.US_WEST_2);
* ddb.setRegion(usWest2);
*
* CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config);
* CreateTableResult createTableResult = ddb.createTable(createTableRequest);
* </pre>
*
* @return Generated create table request.
*/
public static CreateTableRequest getCreateTableRequest(GeoDataManagerConfiguration config) {
CreateTableRequest createTableRequest = new CreateTableRequest()
.withTableName(config.getTableName())
.withProvisionedThroughput(
new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L))
.withKeySchema(
new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(
config.getHashKeyAttributeName()),
new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName(
config.getRangeKeyAttributeName()))
.withAttributeDefinitions(
new AttributeDefinition().withAttributeType(ScalarAttributeType.N).withAttributeName(
config.getHashKeyAttributeName()),
new AttributeDefinition().withAttributeType(ScalarAttributeType.S).withAttributeName(
config.getRangeKeyAttributeName()),
new AttributeDefinition().withAttributeType(ScalarAttributeType.N).withAttributeName(
config.getGeohashAttributeName()),
new AttributeDefinition().withAttributeType(ScalarAttributeType.S).withAttributeName(
config.getBuruMsgAttributeName()))
.withLocalSecondaryIndexes(
new LocalSecondaryIndex()
.withIndexName(config.getGeohashIndexName())
.withKeySchema(
new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(
config.getHashKeyAttributeName()),
new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName(
config.getGeohashAttributeName()))
.withProjection(new Projection().withProjectionType(ProjectionType.ALL)));
return createTableRequest;
}
}
应该使用这些参数创建一个 table:
HashKey
RangeKey
Geohash
BuruMsg
和 range/hash 指数:
Geohash
和 HashKey
但是我的 table 只用 Hash
、Range
和 geohash
构造。它从不添加我的 BuruMsg
属性。
有什么想法吗?
编辑:
这是一张我试图在 AWS 控制台上将项目插入数据库的照片。
DynamoDB 表的架构仅指定散列键、可选范围键和可选索引键。该架构不涵盖未涉及键或索引的属性字段。我相信这就是为什么您的 BuruMsg
字段没有出现在管理控制台 UI 中的原因。你当然可以把数据放到那个字段,你会在管理控制台的项目列表中看到它。
但是定义属性对客户端软件很有帮助,例如Java和.NET ORM 库。你的代码可能没有问题。
我有一个来自 Amazon 的示例 Dynamodb
项目,当上传到 Elastic Beanstalk
环境的实例时,会生成一个 Dynamodb
table。但是,在生成 table 后缺少一些参数。
这是 Elastic Beanstalk
实例的代码:
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.geo.util;
import com.amazonaws.geo.GeoDataManagerConfiguration;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex;
import com.amazonaws.services.dynamodbv2.model.Projection;
import com.amazonaws.services.dynamodbv2.model.ProjectionType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType;
/**
* Utility class.
* */
public class GeoTableUtil {
/**
* <p>
* Construct a create table request object based on GeoDataManagerConfiguration. The users can update any aspect of
* the request and call it.
* </p>
* Example:
*
* <pre>
* AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
* Region usWest2 = Region.getRegion(Regions.US_WEST_2);
* ddb.setRegion(usWest2);
*
* CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config);
* CreateTableResult createTableResult = ddb.createTable(createTableRequest);
* </pre>
*
* @return Generated create table request.
*/
public static CreateTableRequest getCreateTableRequest(GeoDataManagerConfiguration config) {
CreateTableRequest createTableRequest = new CreateTableRequest()
.withTableName(config.getTableName())
.withProvisionedThroughput(
new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L))
.withKeySchema(
new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(
config.getHashKeyAttributeName()),
new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName(
config.getRangeKeyAttributeName()))
.withAttributeDefinitions(
new AttributeDefinition().withAttributeType(ScalarAttributeType.N).withAttributeName(
config.getHashKeyAttributeName()),
new AttributeDefinition().withAttributeType(ScalarAttributeType.S).withAttributeName(
config.getRangeKeyAttributeName()),
new AttributeDefinition().withAttributeType(ScalarAttributeType.N).withAttributeName(
config.getGeohashAttributeName()),
new AttributeDefinition().withAttributeType(ScalarAttributeType.S).withAttributeName(
config.getBuruMsgAttributeName()))
.withLocalSecondaryIndexes(
new LocalSecondaryIndex()
.withIndexName(config.getGeohashIndexName())
.withKeySchema(
new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(
config.getHashKeyAttributeName()),
new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName(
config.getGeohashAttributeName()))
.withProjection(new Projection().withProjectionType(ProjectionType.ALL)));
return createTableRequest;
}
}
应该使用这些参数创建一个 table:
HashKey
RangeKey
Geohash
BuruMsg
和 range/hash 指数:
Geohash
和 HashKey
但是我的 table 只用 Hash
、Range
和 geohash
构造。它从不添加我的 BuruMsg
属性。
有什么想法吗?
编辑:
这是一张我试图在 AWS 控制台上将项目插入数据库的照片。
DynamoDB 表的架构仅指定散列键、可选范围键和可选索引键。该架构不涵盖未涉及键或索引的属性字段。我相信这就是为什么您的 BuruMsg
字段没有出现在管理控制台 UI 中的原因。你当然可以把数据放到那个字段,你会在管理控制台的项目列表中看到它。
但是定义属性对客户端软件很有帮助,例如Java和.NET ORM 库。你的代码可能没有问题。