QasimAshraf
QasimAshraf

Reputation: 99

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?

Upvotes: 6

Views: 1135

Answers (2)

QasimAshraf
QasimAshraf

Reputation: 99

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.

Upvotes: 1

Adi Dembak
Adi Dembak

Reputation: 2546

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

Upvotes: 3

Related Questions