AWSEBCLI 不读取环境变量
Posted
技术标签:
【中文标题】AWSEBCLI 不读取环境变量【英文标题】:AWSEBCLI not reading env vars 【发布时间】:2019-02-25 19:08:59 【问题描述】:我正在尝试在 docker 容器中运行 AWSEBCLI。我将访问密钥和安全令牌作为环境变量传递,如"Configuration Settings and Precedence" 下的文档中所述
ERROR: CredentialsError - Operation Denied. You appear to have no credentials
这是我的 docker 文件
FROM circleci/golang
ADD . /go/src
WORKDIR /go/src
RUN sudo apt-get -y -qq update --assume-yes
RUN sudo apt-get install python-pip python-dev build-essential --assume-yes
RUN sudo pip install awscli=="1.16.9"
RUN sudo pip install awsebcli=="3.14.4"
RUN echo $AWS_ACCESS_KEY_ID
RUN echo $AWS_SECRET_ACCESS_KEY
CMD sudo eb deploy Circledocker
【问题讨论】:
【参考方案1】:您的用户会话和 sudo 会话中定义的环境不一样。
RUN echo $AWS_ACCESS_KEY_ID -> Works
RUN sudo echo $AWS_ACCESS_KEY_ID -> Will not provide you the value.
看看 man sudo,-E 标志:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their
existing environment variables. The security policy may return an error
if the user does not have permission to preserve the environment.
所以这通常有效:
sudo -E bash -c 'echo $AWS_ACCESS_KEY_ID'
试试你的eb deploy
命令:
sudo -E bash -c 'eb deploy Circledocker'
希望对你有帮助!
【讨论】:
以上是关于AWSEBCLI 不读取环境变量的主要内容,如果未能解决你的问题,请参考以下文章
(Nginx +gunicorn)/Apache 不读取环境变量
systemctl 启动某个程序,程序读取某个环境变量不生效的问题