Arpit Shah
Arpit Shah

Reputation: 157

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));

Upvotes: 11

Views: 8885

Answers (3)

user2090166
user2090166

Reputation: 115

Regions.valueOf(awsRegion) should help. Full code:

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

Upvotes: 1

vkstream
vkstream

Reputation: 907

For software.amazon.awssdk use the below code.

 import software.amazon.awssdk.regions.Region;

    Region region= Region.of("Your-Region");

Note: Not for com.amazonaws:aws-java-sdk

Upvotes: 2

Ray Fischer
Ray Fischer

Reputation: 996

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");

Upvotes: 15

Related Questions