Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run `source` in AWS Codebuild

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:

  • Get dependencies
  • Run Tests
  • Get AWS credentials and save to file (detailed below)
  • Source the creds file
  • Run Terraform

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

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

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.

Thanks!

like image 638
Tanishq dubey Avatar asked Jun 28 '17 18:06

Tanishq dubey


People also ask

How do I run CodeBuild?

Retry a build (console) Do one of the following: If the build-project-name : build-ID page is displayed, choose Retry build. In the navigation pane, choose Build history. In the list of builds, select the box for the build, and then choose Retry build.

Where does AWS CodeBuild run your builds?

AWS CodeBuild runs your builds in preconfigured build environments that contain the operating system, programming language runtime, and build tools (e.g., Apache Maven, Gradle, npm) required to complete the task.

Does CodeBuild need a VPC?

Typically, AWS CodeBuild cannot access resources in a VPC. To enable access, you must provide additional VPC-specific configuration information in your CodeBuild project configuration.


1 Answers

Try using . instead of source. source is not POSIX compliant. ss64.com/bash/source.html

like image 107
jeffrey Avatar answered Sep 18 '22 07:09

jeffrey