AWS Elastic Beanstalk - 实例之间的共享计数器变量

AWS Elastic Beanstalk - Shared counter variable between instances

我在启用了自动缩放的 Elastic Beanstalk 上有一个 Python Flask 应用程序 运行。现在我想要一个全局计数器变量,所有 运行 个实例都可以实时访问和更新它。

我已经查看了带有 AWS ElastiCache 的 Redis,但这对我的用例来说似乎有些过分,因为我必须存储一个计数器变量。我还查看了 运行 Redis 在其中一个 Beanstalk 实例上的选项,但这不可行,因为 Beanstalk 可以在缩小规模时关闭实例。

实现此功能的最佳方法是什么?有没有不使用 ElastiCache 的方法?

您是否考虑过使用 Amazon DynamoDB table?

Atomic Counters:

You can use the UpdateItem operation to implement an atomic counter—a numeric attribute that is incremented, unconditionally, without interfering with other write requests. (All write requests are applied in the order in which they were received.) With an atomic counter, the updates are not idempotent. In other words, the numeric value will increment each time you call UpdateItem.

You might use an atomic counter to keep track of the number of visitors to a website. In this case, your application would increment a numeric value, regardless of its current value.