无法在AWS Codebuild中运行`source` [英] Cannot run `source` in AWS Codebuild

查看:133
本文介绍了无法在AWS Codebuild中运行`source`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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凭证并保存到文件(详细信息如下)
  • 获取信用文件
  • 运行Terraform

我遇到困难的地方是获取信用文件".我有一个简单的bash单行代码,它从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等).我在CodeBuild的Python 2.7环境中使用了标准的Ubuntu映像.我该怎么做才能获得Terraform工作凭证,以在Codebuild中获得此凭证文件的来源.

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中运行`source`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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