无法在 AWS Codebuild 中运行“源" [英] Cannot run `source` in AWS Codebuild
问题描述
我正在使用 AWS CodeBuild 和 Terraform 来自动部署基于 Lambda 的服务.我有一个非常简单的 buildscript.yml
可以完成以下任务:
I am using AWS CodeBuild along with Terraform for automated deployment of a Lambda based service. I have a very simple buildscript.yml
that accomplishes the following:
- 获取依赖项
- 运行测试
- 获取 AWS 凭证并保存到文件(详见下文)
- 获取 creds 文件
- 运行 Terraform
获取凭据文件"步骤是我遇到困难的地方.我有一个简单的 bash one-liner,它从 curl 169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
中获取 AWS 容器凭据,然后将它们保存到以下格式的文件中:
The step "source the creds file" is where I am having my difficulty. I have a simply bash one-liner that grabs the AWS container creds off of curl 169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
and then saves them to a file in the following format:
export AWS_ACCESS_KEY_ID=SOMEACCESSKEY
export AWS_SECRET_ACCESS_KEY=MYSECRETKEY
export AWS_SESSION_TOKEN=MYSESSIONTOKEN
当然,显而易见的步骤是简单地 source
这个文件,以便可以将这些变量添加到我的环境中供 Terraform 使用.但是,当我执行 source/path/to/creds_file.txt
时,CodeBuild 会返回:
Of course, the obvious step is to simply source
this file so that these variables can be added to my environment for Terraform to use. However, when I do source /path/to/creds_file.txt
, CodeBuild returns:
[Container] 2017/06/28 18:28:26 Running command source /path/to/creds_file.txt
/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: source: not found
我曾尝试通过 apt
安装 source
,但随后我收到一条错误消息,提示找不到 source
(是的,我已经运行 apt update
等).我将标准 Ubuntu 映像与 Python 2.7 环境一起用于 CodeBuild.我该怎么做才能在 Codebuild 中获取 Terraform 工作凭据以获取此凭据文件.
I have tried to install source
through apt
but then I get an error saying that source
cannot be found (yes, I've run apt update
etc.). I am using a standard Ubuntu image with the Python 2.7 environment for CodeBuild. What can I do to either get Terraform working credentials for source this credentials file in Codebuild.
谢谢!
推荐答案
尝试使用 .
而不是 source
.source
不符合 POSIX.ss64.com/bash/source.html
Try using .
instead of source
. source
is not POSIX compliant. ss64.com/bash/source.html
这篇关于无法在 AWS Codebuild 中运行“源"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!