Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Amazon Global Infrastructure region table (for RestAPI or dotNet)

When the user selects an Amazon service (s3,CloudFront, etc) from a drop-down menu, I'd like to show only those regions/locations available for the selected service.

How can I determine this information? Is there a way to query Amazon's Global Infrastructure region table using RestAPI or dotNet?

like image 321
QasimAshraf Avatar asked Jun 12 '20 14:06

QasimAshraf


People also ask

Which resource or ability is the AWS global infrastructure designed and built to deliver?

The AWS Global Cloud Infrastructure is the most secure, extensive, and reliable cloud platform, offering over 200 fully featured services from data centers globally.

What is the proper structure of an AWS global infrastructure?

Q: What is the proper structure of AWS Global Infrastructure? T: A VPC is your private, logically isolated section of AWS. T: Route Tables are what direct the flow of traffic between resources within a VPC. Q: Availability Zones allow for this type of cloud architecture?

How many regions does AWS currently have in their environment?

The AWS cloud spans 81 Availability Zones within 25 worldwide geographic regions.


2 Answers

AWS Systems Manager can help with this. It has SDKs for various languages as well as a rest API.

For example, to get all the regions for the AWS Athena You can use GetParametersByPath with the path /aws/service/global-infrastructure/services/athena/regions

like image 128
Adi Dembak Avatar answered Nov 15 '22 04:11

Adi Dembak


After answer by @adi-dembak, Here are my steps to achieve this task in .net

Add following SSM Managed Policy in aws and assign policy to user.

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "rule1",
        "Effect": "Allow",
        "Action": [
            "ssm:PutParameter",
            "ssm:GetParametersByPath"
        ],
        "Resource": "*"
    }
]}

Install AWSSDK.SimpleSystemsManagement

        string accessKey = "123##";
        string secretKey = "321##";

        HashSet<string> hash = new HashSet<string>();

        AmazonSimpleSystemsManagementClient amazonSimpleSystemsManagementClient =
            new AmazonSimpleSystemsManagementClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);

        GetParametersByPathRequest getParametersByPathRequest = new GetParametersByPathRequest();
        getParametersByPathRequest.Path = "/aws/service/global-infrastructure/services/s3/regions/";
        getParametersByPathRequest.Recursive = true;

        GetParametersByPathResponse getParametersByPathResponse;

        do
        {
            getParametersByPathResponse = await amazonSimpleSystemsManagementClient.GetParametersByPathAsync(getParametersByPathRequest);
            foreach (Parameter item in getParametersByPathResponse.Parameters)
            {
                hash.Add(item.Value);

            }
            getParametersByPathRequest.NextToken = getParametersByPathResponse.NextToken;
        }
        while ((getParametersByPathResponse.NextToken != null) && !string.IsNullOrEmpty(getParametersByPathResponse.NextToken.ToString()));

        //Print HashSet
        foreach (string item in hash)
        {
            Console.WriteLine(item);
        }

GetParametersByPath is a paged operation. After each call you must retrieve NextToken from the result object, and if it's not null and not empty you must make another call with it added to the request.

like image 34
QasimAshraf Avatar answered Nov 15 '22 04:11

QasimAshraf