DynamoDB 和 TableNameOverride 带前缀

DynamoDB and TableNameOverride with prefix(DynamoDB 和 TableNameOverride 带前缀)
本文介绍了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 表?
我首先想到将它们放在不同的区域,但不确定.

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:

  • 单独查看帐单
  • 确保您绝不在产品和测试系统之间泄露数据
  • 在 dev 表上进行高扩展会阻止您将 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 带前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)