How to get data from aws Dynamodb with using partition key only?

前端 未结 1 1330
暖寄归人
暖寄归人 2021-02-07 11:47

I am using aws-sdk-go library for DynamoDb connectivity in Golang.

My DynamoDb table have a Partition key DeviceId (String) and a Sort Key Time (Number). How can I wri

相关标签:
1条回答
  • 2021-02-07 11:55

    You have to use Query or Scan operation, this is a simple example but you can read more on Amazon documentation here

    In particular, Query operation

    A Query operation finds items in a table or a secondary index using only primary key attribute values

    var queryInput = &dynamodb.QueryInput{
        TableName: aws.String(dynamoRestDataTableName),
        KeyConditions: map[string]*dynamodb.Condition{
            "DeviceId": {
                ComparisonOperator: aws.String("EQ"),
                AttributeValueList: []*dynamodb.AttributeValue{
                    {
                        S: aws.String("aDeviceId"),
                    },
                },
            },
        },
    }
    
    var resp, err = dynamoSvc.Query(queryInput)
    if err != nil {
        return nil, err
    }
    
    0 讨论(0)
提交回复
热议问题