java - 带 Elastic Beanstalk 的 Amazon DynamoDB 表未设置正确的参数

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

我有一个来自 Amazon 的示例 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;
    }
}

这应该创建一个包含以下参数的表: 哈希键 范围键 Geohash BuruMsg

以及范围/散列索引: GeohashHashKey

但是我的表仅使用 HashRangegeohash 构建。它永远不会添加我的 BuruMsg 属性。

有什么想法吗?

编辑:

这是我尝试在 AWS 控制台上将项目插入数据库的图片。 enter image description here

最佳答案

DynamoDB 表的架构仅指定哈希键、可选范围键和可选索引键。该架构不涵盖不涉及键或索引的属性字段。我相信这就是为什么您的 BuruMsg 字段不会出现在管理控制台 UI 中的原因。您当然可以将数据放入该字段,并且您将在管理控制台的项目列表中观察到它。

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

关于java - 带 Elastic Beanstalk 的 Amazon DynamoDB 表未设置正确的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30822848/

相关文章:

java - 将所有常量放在一个类android中

java - 使用ListIterator删除重复项

amazon-web-services - 无法删除 AWS Route53 中的私有(private)托管区域

python-3.x - ClientConnectorCertificateError : Cannot connect to host discordapp. com :443, AWS 上的认证错误。(ec2)

linux - 在EC2启动时自动启动docker-compose

amazon-web-services - AWS : security groups ignoring traffic from elastic IP

java - 虚拟 SD 卡出现问题

对任意数量的整数求和的Java方法

amazon-web-services - 映射的默认值 AWS CloudFormation

tomcat - 监控 Tomcat Web 应用程序