# Metricbeat AWS credentials not working for Non-region endpoint

**URL:** <https://discuss.elastic.co/t/metricbeat-aws-credentials-not-working-for-non-region-endpoint/275191>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [June 7, 2021, 7:29pm UTC](https://discuss.elastic.co/t/metricbeat-aws-credentials-not-working-for-non-region-endpoint/275191 "2021-06-07T19:29:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![swontonsoup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swontonsoup/32/89952_2.png) [@swontonsoup](https://discuss.elastic.co/u/swontonsoup)\
**Post date:** [June 7, 2021, 7:29pm UTC](https://discuss.elastic.co/t/metricbeat-aws-credentials-not-working-for-non-region-endpoint/275191/1 "2021-06-07T19:29:23Z")

</div>

This is similar to [Metricbeat AWS module endpoint not working correctly](https://discuss.elastic.co/t/metricbeat-aws-module-endpoint-not-working-correctly/261589). I tested on 7.13.1, but I think this should persist to current master branch.

So I tried 3 different configurations and am unable to get the desired metricbeat stats for AWS. First, my aws.yml contains endpoint, region, and role\_arn (endpoint and region are examples - not exactly what is used):

```auto
- module: aws
  period: 300s
  endpoint: amazonaws.com.cn
  regions: cn-north-1
  metricsets:
    - ec2
  role_arn: "arn:aws:iam::ACCOUNT_NUM:role/instance_role"

```

I would expect it to call [sts.cn-north-1.amazonaws.com.cn](http://sts.cn-north-1.amazonaws.com.cn) for verification, but instead, it still calls [sts.amazonaws.com](http://sts.amazonaws.com), which wouldn't exist. Looking into the libbeat/common/aws/credentials.go code, I then removed the role\_arn and tried the following aws.yml:

```auto
- module: aws
  period: 300s
  endpoint: amazonaws.com.cn
  regions: cn-north-1
  metricsets:
    - ec2

```

This way, it should be able to authenticate using the instance profile (without specifying the role ARN). It's able to get pass the STS check from libbeat/common/aws/credentials.go:111, but then future services end up duplicating the region (e.g. it calls '[ec2.cn-north-1.cn-north-1.amazonaws.com.cn](http://ec2.cn-north-1.cn-north-1.amazonaws.com.cn)' instead of '[ec2.cn-north-1.amazonaws.com.cn](http://ec2.cn-north-1.amazonaws.com.cn)'). To get around this, I omitted the region and instead prefixed it onto the endpoint field:

```auto
- module: aws
  period: 300s
  endpoint: cn-north-1.amazonaws.com.cn
  metricsets:
    - ec2

```

However, when it tries the STS verification, it now complains about a mismatched region (us-east-1 vs cn-north-1).

I think part of the issue is at `x-pack/libbeat/common/aws/credentials.go`:98 where the region is set initially to 'us-east-1'. When the role arn is empty, it then attempts to use STS with us-east-1, which then fails because the region doesnt exist for me.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2021, 9:30pm UTC](https://discuss.elastic.co/t/metricbeat-aws-credentials-not-working-for-non-region-endpoint/275191/2 "2021-07-05T21:30:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
