Question: I wish to write an SQL statement for SQL Server that Selects entry's from a column witch contains a value sum of power of 2 (2^n), 
for instance I have TABLE xxx:

```sql
_________________________________________________________
| id | col_pow |col_pow=sum of element power of 2 (2^n) |
|----|---------|----------------------------------------|
| 1  | 11      |11  = 8+2+1   = 2^3 + 2^1 +2^0          |           
| 2  | 3       |3   = 2+1     = 2^1 + 2^0               |
| 3  | 514     |514 = 512+2   = 2^9 + 2^1               |
| 4  | 49      |49  = 32+16+1 = 2^5 + 2^4 +2^0          |
| 5  | 7       |7   = 4+2+1   = 2^2 + 2^1 +2^0          |
---------------------------------------------------------

```

EX. SELECT

1) `SELECT id TABLE xxx WHERE col_pow can_contains 4 (=2^2)`

* expected result:

```sql
| id |
|----|
| 5  |

```

2) `SELECT id TABLE xxx WHERE col_pow can_contains 2 (=2^1)`

* expected result:

```sql
| id |
|----|
| 1  |
| 2  |
| 3  |
| 4  |
| 5  |

```

3) `SELECT id TABLE xxx WHERE col_pow can_contains 512(=2^9)`

* expected result:

```sql
| id |
|----|
| 3  |

```

How to write the 3 statements?

Answer: 
I use `aws iam get-account-authorization-details` to view the current IAM roles in my AWS China accounts, which are created using AWS console.

Then I found lines containing `"Service": "ec2.amazonaws.com.cn"`.

So using `ec2.amazonaws.com.cn` to replace `ec2.amazonaws.com` works without any problem.

I mean the content of `main.tf` should be

```
provider "aws" {
  access_key = var.access_key
  secret_key = var.secret_key
  region  = var.region
}

resource "aws_iam_role" "role" {
  name               = "TestRole"
  assume_role_policy = data.aws_iam_policy_document.policy_doc.json
}

data "aws_iam_policy_document" "policy_doc" {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type        = "Service"
      identifiers = ["ec2.amazonaws.com.cn"]
    }
  }
}

```
Like so much in AWS, it is all fully documented... but the real challenge is in finding [the documentation](https://docs.amazonaws.cn/en_us/aws/latest/userguide/endpoints-Ningxia.html).

As you wrote, Brian, the answer is to use `ec2.amazonaws.com.cn` instead of `ec2.amazonaws.com` when working in China. But I thought the documentation above might be helpful since it includes all mappings.

---

Also, highly related:

If you use Terraform and you need to manage resources both in China and outside, you can use the data source `aws_partition` to help you generalize across China and non-China:

```
data "aws_partition" "current" {
}

data "aws_caller_identity" "current" {
}

```

Then later if you have something like:

```
    principals {
      type        = "AWS"
      identifiers = ["arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/my_cool_role"]
    }

```

Then it will evaluate the ARN as follows:

* China: `arn:aws-cn:iam::<my China account number>:role/my_cool_role`
* Anywhere else: `arn:aws:iam::<my other account number>:role/my_cool_role`

Note that in China it's `aws-cn` whereas it is `aws` otherwise.

This does assume that you have properly set up the two regions, so that "current" reflects back to the Chinese and non-Chinese accounts.