2015-06-13 15 views
0

我有一個例子Dynamodb項目從亞馬遜,當上傳到Elastic Beanstalk環境的一個實例,生成一個Dynamodb表。 Howevever在生成表格後缺少一些參數。亞馬遜DynamoDB表w/Elastic Beanstalk沒有設置正確的參數

下面是代碼的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

和範圍/散列索引: Geohash and HashKey

但是我的表格只構造了Hash,Rangegeohash。它永遠不會添加我的BuruMsg屬性。

任何想法?

編輯:

這裏是我的嘗試插入一項關於AWS控制檯數據庫中的圖片。 enter image description here

回答

1

DynamoDB表的模式僅指定散列鍵,可選範圍鍵和可選索引鍵。該架構不包括不受密鑰或索引影響的屬性字段。我相信這就是爲什麼你的BuruMsg字段沒有出現在管理控制檯UI中。您當然可以將數據放入該字段,並且您將在管理控制檯的項目清單中觀察它。

但是定義屬性對客戶端軟件很有幫助,例如Java和.NET ORM庫。你的代碼可能沒有問題。