如何实现具有每日价值的简单dynamodb表 [英] How to implement simple dynamodb table with daily value

查看:96
本文介绍了如何实现具有每日价值的简单dynamodb表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过构建一个非常简单的API项目来学习AWS API Gateway + Lambda + Dynamodb。

I'am learning AWS API Gateway + Lambda + Dynamodb by building a very simple API project.

我的每日价值从2013年1月1日开始,并且每天都在不断更新,所以基本上是这样的:

I have a daily value starting from 2013-01-01 and keep updating every day, so basically is something like:

[
    {
        "value": 1776.09,
        "date": "2013-01-01"
    },
    {
        "value": 1779.25,
        "date": "2013-01-02"
    },
    // ...
    {
        "value": 2697.32,
        "date": "2018-11-22"
    }
]

在API中,我想获取特定日期的数据并范围(dateFrom-dateTo),我一直在阅读有关Dynamodb的内容,并计划将 date 作为分区键,格式为 YYYY-MM- DD 且没有排序键,但是不确定这是否适合此类型的数据和范围查询,因为我假设我将必须执行对范围查询进行全表扫描,尽管这是一个小数据集。

In the API I want to get the data for a specific day and for a range (dateFrom - dateTo), and I've been reading about Dynamodb and planning to have date as partition key in format YYYY-MM-DD and no sorting key, but not sure if this is the correct aproach for this type of data and the range query I'm going to be doing as I assume I'm going to have to do a full table scan for the range query, although is a small data set.

有人可以指出这个方法是否正确,还是需要重新考虑我的表结构。

Can someone point me if this aproach is right or do I need to reconsider my table structure.

推荐答案

您的建议将起作用。

但是,如果要提高设计效率,可以使用 YYYY 分区键,然后那么您的排序键可能是 MM-DD 。这样,您可以使用查询操作来限制结果(或者您仍然可以使用扫描)。

However, if you want to improve the efficiency of the design, you could use a partition key of YYYY and then your sort key could be MM-DD. That way, you can use a query operation to limit the results (or you could still use a scan).

您甚至可以为分区键使用单个恒定值,并使用 date 作为排序键,但是通常不建议为每个项目使用相同的分区键。

You could even use a single, constant value for the partition key and date as the sort key, but having the same partition key for every item is generally not recommended.

无论哪种方式,您的数据都足够小,您可能应该只选择最易于开发和维护的实现。

Either way, your data is small enough that you should probably just pick the implementation that is simplest to develop and maintain.

这篇关于如何实现具有每日价值的简单dynamodb表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆