英文:
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
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论