Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS: Convert String to Region

I do not want to hardcode region id and pass region name as String from command line. Is there a way to do that? Hardcoding:

Region s3Region = Region.getRegion(Regions.US_EAST_1); 
Non Hardcoded but not working:
Region s3Region = Region.getRegion(Regions.fromName(awsRegion));
like image 218
Arpit Shah Avatar asked Mar 13 '15 00:03

Arpit Shah


2 Answers

Answering the question that I think you mean to ask:

If you have an Amazon region name like, for example, "us-east-1" then you can easily convert it to a RegionEndpoint:

RegionEndpoint endpoint = Amazon.RegionEndpoint.GetBySystemName("us-east-1");
like image 104
Ray Fischer Avatar answered Sep 28 '22 12:09

Ray Fischer


May its very late to reply but Regions.valueOf(awsRegion) should help! So full code should be :

Region s3Region = Region.getRegion(Regions.valueOf(awsRegion.toUpperCase()));

Hope this helps.

like image 26
user2090166 Avatar answered Sep 28 '22 12:09

user2090166