简体   繁体   English

使用AWS Cli访问DynamoDB中的AWS Kinesis表

[英]Access to AWS Kinesis tables in DynamoDB using AWS Cli

I am new to AWS Kinesis. 我是AWS Kinesis的新手。 Trying to learn how to build distributed application using AWS DynamoDB. 尝试学习如何使用AWS DynamoDB构建分布式应用程序。 Could someone tell me how to access the tables in DynamoDB used by my streams in AWS Kinesis using the AWS Cli? 有人可以告诉我如何使用AWS Cli访问我在AWS Kinesis中的流所使用的DynamoDB中的表吗? Can I query the tables? 我可以查询表格吗?

Surely. 一定。 Kinesis-stream uses Amazon Dynamodb table for consumer offset management. Kinesis-stream使用Amazon Dynamodb表进行消费者补偿管理。

  • your table will have the same name as your consumer name (defined via KCL). 您的表将具有与您的使用者名称相同的名称(通过KCL定义)。 you can see all consumer_offset_tables via console ( https://console.aws.amazon.com/dynamodb/home ) 您可以通过控制台( https://console.aws.amazon.com/dynamodb/home )查看所有consumer_offset_tables

  • consumer could be running in multiple instances, but only one instance (THE leaseOwner )can consume from one partition (or Shard what Kinesis calls it). 消费者可以在多个实例中运行,但是只有一个实例( leaseOwner )可以从一个分区(或leaseOwner称为Kinesis)使用。 If this consumer fails another instance of the same consumer will take over and continue processing from the checkpoint . 如果此使用方失败,则同一使用方的另一个实例将接管并继续从checkpoint进行处理。

  • checkpoint is the last processed event 检查点是最后处理的事件
  • the shard that the consumer instance is processing is called leaseKey which is unique for a table. 使用者实例正在处理的分片称为leaseKey ,它对于表是唯一的。

  • The data structure of the key value based document in Dynamodb would be as below, Dynamodb中基于键值的文档的数据结构如下所示,

where 哪里

"S" - Char array

"N" - Number

{
  "leaseOwner": {
    "S": "SmartConsumerStream_Consumer-192.168.1.83"
  },
  "checkpoint": {
    "S": "49570630332110756564477900867375857710984404992079691778"
  },
  "checkpointSubSequenceNumber": {
    "N": "0"
  },
  "leaseCounter": {
    "N": "16"
  },
  "leaseKey": {
    "S": "shardId-000000000000"
  },
  "ownerSwitchesSinceCheckpoint": {
    "N": "0"
  }
}
  • You can use Dynamodb API to get the current offset for given partitionKey or leaseKey . 您可以使用Dynamodb API来获取给定partitionKeyleaseKey的当前偏移量。 You can only query by leaseKey because thats the indexed key in table. 您只能通过leaseKey查询,因为那就是表中的索引键。 Its created by Kinesis-stream itself. 它由Kinesis-stream本身创建。

  • You can use the stream-driver I'm writing at here , which gives you interface to get the consumer offset very very easily. 您可以使用我在此处编写的流驱动程序它为您提供了非常非常容易获得使用者补偿的界面。

  • Here are kinesis-stream tests which might be helpful too. 这是运动学流测试 ,可能也有帮助。

In summary, get the consumer offset using JAVA api 总而言之,使用JAVA API获取使用者偏移量

-- put aws credentials in ~/.aws/credentials -将~/.aws/credentials凭证放入~/.aws/credentials

public Map<String, String> getConsumerPosition() {
    DynamoDB dynamoDB = new DynamoDB(getOffsetConnection()); //
    Table consumerOffsetTable = dynamoDB.getTable("your_consumer_id");

    Map<String, Object> leaseOwner = consumerOffsetTable.getItem("leaseKey", "shardId-000000000000").asMap();

    return new HashMap<String, String>(){{
        put(leaseOwner.get("leaseKey").toString(), leaseOwner.get("checkpoint").toString());
    }};
}

public AmazonDynamoDB getOffsetConnection() {
    AmazonDynamoDBClient dynamoDB = new AmazonDynamoDBClient(getAuthProfileCredentials(), getHttpConfiguration());

    return dynamoDB;
}

private ProfileCredentialsProvider getAuthProfileCredentials() {
    return new ProfileCredentialsProvider("your-aws-auth-profile_in_~/.aws/credentials");
}


private ClientConfiguration getHttpConfiguration() {

    ClientConfiguration clientConfiguration = new ClientConfiguration();

    return clientConfiguration;
}

Hope it helps, let me know if I can help some other ways. 希望对您有所帮助,请告知我是否可以通过其他方式帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM