AWS CLI在使用Golang运行命令时出现错误。

huangapple go评论84阅读模式
英文:

AWS CLI error while running command from Golang

问题

我正在尝试使用Golang的os/exec包中的命令函数来运行AWS命令。但是在执行时出现错误。

命令: aws s3 cp SOURCE_DIR s3://BUCKET_NAME/TARGET_DIR --recursive

错误: 无法找到凭证

但是凭证已经设置为“共享配置文件”。请指导我在这里做错了什么,以及如何解决这个问题。

英文:

I am trying to run aws command using Golang's command function in os/exec package. But it gives error on doing so.

command: aws s3 cp SOURCE_DIR s3://BUCKET_NAME/TARGET_DIR --recursive

error: Unable to locate credentials

But credentials are set as shared configuration file. Please guide me what I am doing wrong here and how it can be resolved.

答案1

得分: 0

假设Go程序以正确的用户身份运行,请尝试执行aws configure list命令。

此线程所解释的那样,您将看到凭据是如何配置的:

  • 配置文件
  • 环境变量
  • 实例配置文件
  • 或者...在Go运行时会话的上下文中根本没有配置。

> 另外,凭据文件是由不同的用户拥有,而要复制的目录是由不同的用户拥有。这可能是问题吗?

是的,这就是这个答案的重点:在Go程序执行期间,仔细检查它所看到的环境变量(如$HOME)。

英文:

Assuming the Go program is run with the right user, try and execute instead aws configure list

As explained in this thread, you will see how your credentials are configured:

  • config file
  • environment variable
  • instance profile
  • or... not at all, in the context of your Go runtime session.

> Also the credentials file is with a different user and the directory which is being copied is with different user. can this be the issue ?

Yes, that is the point of this answer: double-check what your Go program sees during its execution, in term of environment variable (like $HOME).

huangapple
  • 本文由 发表于 2021年11月22日 11:22:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/70060560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定