我在我的groovy脚本中使用AWS api:
new AmazonDynamoDBClientBuilder ()
.withRegion(Regions.SA_EAST_1)
.build()
我希望能够将该区域作为用户参数传递给脚本,但Regions是枚举。如何将区域(如“SA_EAST_1”或“CN_NORTH_1”)作为字符串传递?我可以使用自己的地图将字符串值转换为枚举值,但这看起来真的很蠢。
答案 0 :(得分:2)
// convert the enum value to a string using name
String name = Region.SA_EAST_1.name();
// convert the string to a enum value
Region value = Region.valueOf(name);