如何获取AWSSDK.DynamoDBv2

时间:2016-06-22 17:27:41

标签: c# servicestack amazon-dynamodb pocodynamo

我正在使用ServiceStack.Aws并且我收到了ResourceNotFoundException,但我看不到它要查找的资源名称。 ¿资源名称是在异常中发送的? ¿我怎么能得到它?

我的模型类是(表和索引名称存在)

[DynamoDBTable("SOME-TABLE-NAME")]
    public class Company
    {
        [DynamoDBHashKey]
        public string CompanyId { get; set; }

        [DynamoDBGlobalSecondaryIndexHashKey("SOME-INDEX-NAME")]
        public string ShortName { get; set; }

        public string DocumentNumber { get; set; }
        public string FullName { get; set; }
        public string Address { get; set; }
        public DateTime CreatedAt { get; set; }
    }

我的代码是

var awsDb = new AmazonDynamoDBClient();
            var db = new PocoDynamo(awsDb);

            db.RegisterTable<Company>();
            try
            {
                db.PutItem<Company>(new Company
                {
                    Address = "Some address #some number",
                    CompanyId = Guid.NewGuid().ToString(),
                    CreatedAt = DateTime.Now,
                    DocumentNumber = "11.222.333-4",
                    FullName = "Some company name",
                    ShortName = "ShortName"
                });
            }
            catch (ResourceNotFoundException ex)
            {

            }
            catch (Exception ex)
            {

            }

在我的app.config中我有(路径和配置文件名称存在。区域也可以)

<aws region="us-east-1" profileName="profile-name" profilesLocation="some-path\certificados.txt">
  </aws>

编辑:问题是ServiceStack不使用AWS属性。所以,我将DynamoDBTable更改为Alias,一切正常

1 个答案:

答案 0 :(得分:1)

ServiceStack.Aws's PocoDynamo会在幕后自动重试临时异常,因此可能会重试原始AWS异常。我刚刚在this commit中添加了ExceptionFilter,您可以通过以下方式检查AWS DynamoDB客户端抛出的每个异常:

var dynamo = new PocoDynamo(awsDynamoClient) { 
    ExceptionFilter = ex => ex.Message.Print();
};

ExceptionFilter可从v4.0.61获得,现在是available on MyGet

同样[DynamoDBGlobalSecondaryIndexHashKey]属性对PocoDynamo无效,请参阅creating Global Indexes with PocoDynamo上的文档。