使用AWS CLI进行Bash-无法找到凭证 [英] Bash with AWS CLI - unable to locate credentials

查看:68
本文介绍了使用AWS CLI进行Bash-无法找到凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Shell脚本,应该从S3下载一些文件并挂载ebs驱动器.但是,我总是以无法找到凭据"结尾.

I have a shell script which is supposed to download some files from S3 and mount an ebs drive. However, I always end up with "Unable to locate credentials".

我已经使用 aws configure 命令指定了我的凭据,并且这些命令在Shell脚本之外运行.有人可以(最好是详细地)告诉我如何使其工作吗?

I have specified my credentials with the aws configure command and the commands work outside the shell script. Could somebody, please, tell me (preferably in detail) how to make it work?

这是我的剧本

#!/bin/bash

AWS_CONFIG_FILE="~/.aws/config"

echo $1

sudo mkfs -t ext4 $1
sudo mkdir /s3-backup-test
sudo chmod -R ugo+rw /s3-backup-test
sudo mount $1 /s3-backup-test

sudo aws s3 sync s3://backup-test-s3 /s3-backup/test

du -h /s3-backup-test
ipt (short version):

感谢您的帮助!

推荐答案

sudo 将更改 $ HOME 目录(并因此更改)到/root,并从环境中删除大多数bash变量,例如AWS_CONFIG_FILE.确保以root身份或用户身份使用aws进行所有操作,不要混用.

sudo will change the $HOME directory (and therefore ~) to /root, and remove most bash variables like AWS_CONFIG_FILE from the environment. Make sure you do everything with aws as root or as your user, dont mix.

例如,确保您已完成 sudo aws configure .并尝试

Make sure you did sudo aws configure for example. And try

sudo bash -c 'AWS_CONFIG_FILE=/root/.aws/config aws s3 sync s3://backup-test-s3 /s3-backup/test'

您可能更喜欢从脚本内部删除所有sudo,而仅对脚本本身进行sudo.

You might prefer to remove all the sudo from inside the script, and just sudo the script itself.

这篇关于使用AWS CLI进行Bash-无法找到凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆