本文介绍了带前缀的DynamoDB和TableNameOverride的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试DynamoDB表,并希望使用前缀dev_进行开发,为prod和dev环境设置不同的表名。

I am testing DynamoDB tables and want to set up different table names for prod and dev environment using the prefix "dev_" for development.

我做了这个测试打印表名:

I made this test to print the table name:

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig.TableNameOverride;  

TableNameOverride tbl = new TableNameOverride("test").withTableNamePrefix("dev_");
System.out.println("name=" + tbl.getTableName() + "  prefix=" + tbl.getTableNamePrefix());

打印: name = null prefix = dev _

为什么这里的名字为空?

This prints: name=null prefix=dev_
How come the name here is null ?

TableNameOverride tbl = new TableNameOverride("test");//.withTableNamePrefix("dev_");
System.out.println("name=" + tbl.getTableName() + "  prefix=" + tbl.getTableNamePrefix());

打印: name = test prefix = null

* 如何将表名称设为dev_test?*

我想稍后使用它来为开发模式中的所有表获取dev_前缀,如下所示:

I want to use this later to get a "dev_" prefix for all tables in development mode like this:

DynamoDBTable annotation = (DynamoDBTable) myclass.getClass().getAnnotation(DynamoDBTable.class);  
TableNameOverride tbl = new TableNameOverride(annotation.tableName()).withTableNamePrefix("dev_");

还是有另一种解决方案可以分开dev和prod表吗?

I首先考虑将它们放在不同的区域但不确定。

Or is there another solution to separate between dev and prod tables?
I first thought of putting them in separate regions but not sure about this.

也可以使用它:

mapper.save(ck, new DynamoDBMapperConfig(new TableNameOverride((isDev ? "dev_" : "") + annotation.tableName())));


推荐答案

withTableNamePrefix 是一种静态方法。因此,这一行使用字符串test创建 TableNameOverride 的新实例,然后通过使用它来调用静态 withTableNamePrefix来抛弃该实例方法:

withTableNamePrefix is a static method. So this line is creating a new instance of TableNameOverride with the String "test", and then throwing that instance away by using it to call the static withTableNamePrefix method:

TableNameOverride tbl = new TableNameOverride("test").withTableNamePrefix("dev_");

为了回答将测试与产品分离的更深层次的问题,我建议完全使用2个独立的AWS账户,一个用于开发,一个用于产品。这是唯一的方法:

To answer the deeper question of separating test from prod, I would recommend having 2 separate AWS Accounts entirely, one for dev and one for prod. This is the only way you can:


  • 单独查看结算

  • 确保从不 prod和测试系统之间的泄漏数据

  • 在开发表上进行高扩展会阻止您更高地扩展prod表

  • See billing separately
  • Ensure you never leak data between prod and test systems
  • Have high scaling on a dev table prevent you from scaling a prod table higher

这篇关于带前缀的DynamoDB和TableNameOverride的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 20:39