If you want to get the region using JS, this should work:
meta.request("/latest/meta-data/placement/availability-zone",function(err,data){ if(err) console.log(err); else{ console.log(data); str = data.substring(0, data.length - 1); AWS.config.update({region:str}); ec2 = new AWS.EC2(); } });
This mapping, found from AWS DOCS, in response to a metadata API call, just trimming the last character should work.
eu-west-1a :eu-west-1 eu-west-1b :eu-west-1 eu-west-1c :eu-west-1 us-east-1a :us-east-1 us-east-1b :us-east-1 us-east-1c :us-east-1 us-east-1d :us-east-1 ap-northeast-1a :ap-northeast-1 ap-northeast-1b :ap-northeast-1 us-west-1a :us-west-1 us-west-1b :us-west-1 us-west-1c :us-west-1 ap-southeast-1a :ap-southeast-1 ap-southeast-1b :ap-southeast-1
Surya Prakash Patel Jun 20 '17 at 13:11 2017-06-20 13:11
source share