繁体   English   中英

运行本地 Cloudwatch 代理时出现“无法确定 aws-region”

[英]"Unable to determine aws-region" when running on-premises Cloudwatch agent

我正在尝试将 AWS Cloudwatch 代理配置为在 AWS 之外的 vanilla Ubuntu 18.04 上运行。 每次运行它时,我都会收到此错误:

# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c "file:/path/to/cloudwatch/cloudwatch.json" -s
/opt/aws/amazon-cloudwatch-agent/bin/config-downloader --output-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --download-source file:/path/to/cloudwatch/cloudwatch.json --mode onPrem --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default
Got Home directory: /root
I! Set home dir Linux: /root
Unable to determine aws-region.
Please make sure the credentials and region set correctly on your hosts.
Refer to http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
Fail to fetch the config!

strace -f下运行程序显示它正在尝试读取/root/.aws/credentials然后退出。 根据指南,这里是/root/.aws/credentials的内容:

[AmazonCloudWatchAgent]
aws_access_key_id = key
aws_secret_access_key = secret
region = us-west-2

如果我运行aws configure get region ,它能够正确检索区域。 但是,Cloudwatch 代理无法读取它。 这是common-config.toml的内容(每个 strace 也会读取它)。

## Configuration for shared credential.
## Default credential strategy will be used if it is absent here:
##  Instance role is used for EC2 case by default.
##  AmazonCloudWatchAgent profile is used for onPremise case by default.
[credentials]
   shared_credential_profile = "AmazonCloudWatchAgent"
   shared_credential_file = "/root/.aws/credentials"


## Configuration for proxy.
## System-wide environment-variable will be read if it is absent here.
## i.e. HTTP_PROXY/http_proxy; HTTPS_PROXY/https_proxy; NO_PROXY/no_proxy
## Note: system-wide environment-variable is not accessible when using ssm run-command.
## Absent in both here and environment-variable means no proxy will be used.
# [proxy]
#    http_proxy = "{http_url}"
#    https_proxy = "{https_url}"
#    no_proxy = "{domain}"

这是我尝试过的其他事情:

  • 根据https://forums.aws.amazon.com/thread.jspa?threadID=291589 ,用双引号将配置中的region (和所有值)括起来。 这并没有什么不同。

  • 添加 /home/myuser/.aws/config、/home/myuser/.aws/credentials 和 /root/.aws/config 并用适当的值填充它们。 根据 strace 这些文件没有被读取。

  • 搜索 CloudWatch 代理的源代码(它不是开源的)

  • 在程序环境中显式设置 AWS_REGION=us-west-2(同样的错误)

  • [AmazonCloudWatchAgent]更改为[profile AmazonCloudWatchAgent]以及上述所有排列(无区别)

  • 在所有配置文件中添加[default]部分(没有区别)

  • 直接调用config-downloader程序,设置AWS_REGION等(同样的错误)

  • 成为非 root 用户,然后使用sudo调用程序,而不是在没有sudo的情况下以 root 用户身份调用程序。

无论我尝试什么,我都会遇到同样的错误。 我按照这些说明于 2020 年 3 月 23 日通过下载“最新”deb 安装了 CloudWatch 代理。 https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html

aws 配置默认为 C:\\Users\\Administrator,而不是您安装 CloudWatch 代理的用户。 因此,您可能需要将 /.aws/ 文件夹移动到 CLoudWatch 用户。 或者……更直接:

aws configure --profile AmazonCloudWatchAgent

如此处所述: https : //docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html#install-CloudWatch-Agent-iam_user-first

您还可以使用common-config.toml指定区域,如下所述: https : //docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html#CloudWatch-Agent-配置文件实例优先

在运行 Windows Server 的服务器上,此文件位于 C:\\ProgramData\\Amazon\\AmazonCloudWatchAgent 目录中。 默认的 common-config.toml 如下:

# This common-config is used to configure items used for both ssm and cloudwatch access


## Configuration for shared credential.
## Default credential strategy will be used if it is absent here:
##            Instance role is used for EC2 case by default.
##            AmazonCloudWatchAgent profile is used for onPremise case by default.
# [credentials]
#    shared_credential_profile = "{profile_name}"
#    shared_credential_file= "{file_name}"

## Configuration for proxy.
## System-wide environment-variable will be read if it is absent here.
## i.e. HTTP_PROXY/http_proxy; HTTPS_PROXY/https_proxy; NO_PROXY/no_proxy
## Note: system-wide environment-variable is not accessible when using ssm run-command.
## Absent in both here and environment-variable means no proxy will be used.
# [proxy]
#    http_proxy = "{http_url}"
#    https_proxy = "{https_url}"
#    no_proxy = "{domain}"

如果需要,您还可以使用新位置更新 common-config.toml。

我使用了一个不正确的“秘密”和一个无效字符,导致 INI 文件解析器中断。 CloudWatch 代理错误地将此报告为“缺失区域”,而解析错误或“密码无效”错误会更准确。

您应该在与凭据相同的文件夹中创建一个名为config的新文件

并在那里添加区域

[default]
region = your-region

在这里查看更多

您还必须取消注释/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml配置文件中的# [credentials]

设置 AWS_REGION 环境变量。

在 Linux、macOS 或 Unix 上,使用:export AWS_REGION=your_aws_region

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM