具有Elastic Beanstalk的Amazon DynamoDB表未设置正确的参数

时间:2015-06-13 19:46:45

标签: java amazon-web-services amazon-ec2 amazon-dynamodb

我有一个来自亚马逊的示例Dynamodb项目,当上传到Elastic Beanstalk环境的实例时,会生成一个Dynamodb表。然而,在生成表之后,缺少一些参数。

以下是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;
    }
}

哪个应该创建一个包含以下参数的表: HashKey RangeKey Geohash BuruMsg

和范围/哈希索引: GeohashHashKey

但是,我的表格仅使用HashRangegeohash进行构建。它从不添加我的BuruMsg属性。

有什么想法吗?

编辑:

以下是我尝试将项目插入AWS Console数据库的图片。 enter image description here

1 个答案:

答案 0 :(得分:1)

DynamoDB表的架构仅指定散列键,可选范围键和可选索引键。架构不包括未包含在键或索引中的属性字段。我相信这就是您的BuruMsg字段未出现在管理控制台UI中的原因。您当然可以将数据放入该字段,您将在管理控制台的项目列表中观察它。

但定义属性对客户端软件很有帮助,例如Java和.NET ORM库。您的代码可能没有任何问题。