Skip to content

Get $awsregion and $awsdomain within aws linux 2023

1

The /etc/yum.repos.d/amazonlinux.repo file within aws ec2 linux 2023 contains URLs like https://al2023-repos-$awsregion-de612dc2.s3.dualstack.$awsregion.$awsdomain that includes the variables $awsregion and $awsdomain. Where are this variables declared or how those vars are resolved, when using yum?

I know I can get both strings from AWS console. But how to determine them within the aws linux system?

asked 3 years ago1.5K views
2 Answers
3

Hello

The directory /etc/yum/vars defines the custom yum variables. The directory must include the variables awsdomain and awsregion. You can able to get these values mapped to these variables from the path "cat /etc/dnf/vars/awsregion" and "cat /etc/dnf/vars/awsdomain"

$ cat /etc/yum/vars/awsregion us-east-1

$ cat /etc/yum/vars/awsdomain amazonaws.com

you can refer this article: https://repost.aws/knowledge-center/ec2-troubleshoot-yum-errors-al1-al2

AWS
answered 3 years ago
  • /etc/yum/ is no such file or directory. And the result of cat /etc/dnf/vars/awsdomain is empty. Same for cat /etc/dnf/vars/awsregion.

1

Please check the following links

https://repost.aws/knowledge-center/ec2-troubleshoot-yum-errors-al1-al2 https://stackoverflow.com/questions/31331788/using-aws-cli-what-is-best-way-to-determine-the-current-region https://stackoverflow.com/questions/53473321/where-to-find-domain-name-to-existing-ec2-instance

as a summary

To get the AWS region, you can use one of the following commands:

aws configure get region

If you are using a profile, then type

aws configure get region --profile $PROFILE_NAME​

You can get the current availability zone via an instance metadata and extract the region part from it using this command

curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/\(.*\)[a-z]/\1'​

You can also use this AWS CLI command which gives the region actually used by the CLI regardless of whether environment variables are or are not set:

aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]'​

To get the AWS domain is more complex as it is not typically stored as a variable within the system. It could be related to the DNS service used and the specific AWS services (like load balancers) associated with the instance. In AWS, it's often linked to Route53, the AWS managed DNS service. You could find the domain associated with an instance by checking the Route53 service in AWS console​3​. But usually, the domain part for AWS Linux repository URLs tends to be amazonaws.com.

EXPERT
answered 3 years ago
  • My question is more about how yum knows the correct repo location from /etc/yum.repos.d/amazonlinux.repo, if the link to the repo https://al2023-repos-$awsregion-de612dc2.s3.dualstack.$awsregion.$awsdomain contains variables, which can not resolved by yum it self?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.