title: Why are my AWS CodeBuild commands not running?
body: <p>I am trying to use AWS CodeBuild for my project.  My build is running on the <code>aws/codebuild/docker:1.12.1</code> image.  This is my <code>buildspec.yml</code>, which was taken from the <a href="http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html" rel="nofollow noreferrer">AWS Docker Sample</a></p>
  
  <pre><code>version: 0.1
  
  phases:
    pre_build:
      commands:
        - echo Logging in to Amazon ECR...
        - $(aws ecr get-login --region $AWS_DEFAULT_REGION)
    build:
      commands:
        - echo Build started on `date`
        - echo Building the Docker image...          
        - docker build -t $IMAGE_REPO_NAME .
    post-build:
      commands:
        - echo Build completed on `date`
        - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
        - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
  </code></pre>
  
  <p>All of the environment variables are defined in the build configuration.  But this is my CodeBuild log output:</p>
  
  <pre><code>[Container] 2017/02/16 22:04:24 Waiting for agent
  [Container] 2017/02/16 22:04:33 Phase is DOWNLOAD_SOURCE
  [Container] 2017/02/16 22:04:34 Source is located at /tmp/src733484785/src
  [Container] 2017/02/16 22:04:34 YAML location is /tmp/src733484785/src/buildspec.yml
  [Container] 2017/02/16 22:04:34 Registering with agent
  [Container] 2017/02/16 22:04:34 Phases found in YAML: 3
  [Container] 2017/02/16 22:04:34 PRE_BUILD: 2 commands
  [Container] 2017/02/16 22:04:34 BUILD: 3 commands
  [Container] 2017/02/16 22:04:34 POST-BUILD: 3 commands
  [Container] 2017/02/16 22:04:34 Phase complete: DOWNLOAD_SOURCE Success: true
  [Container] 2017/02/16 22:04:34 Phase context status code: Message: 
  [Container] 2017/02/16 22:04:34 Processing plaintext environment variables
  [Container] 2017/02/16 22:04:34 Processing build-level environment variables
  [Container] 2017/02/16 22:57:53 {"AWS_DEFAULT_REGION":"&lt;censored&gt;","AWS_ACCOUNT_ID":"&lt;censored&gt;","IMAGE_TAG":"&lt;censored&gt;","IMAGE_REPO_NAME":"&lt;censored&gt;"}
  [Container] 2017/02/16 22:57:53 AWS_DEFAULT_REGION = &lt;censored&gt;
  [Container] 2017/02/16 22:57:53 AWS_ACCOUNT_ID = &lt;censored&gt;
  [Container] 2017/02/16 22:57:53 IMAGE_TAG = &lt;censored&gt;
  [Container] 2017/02/16 22:57:53 IMAGE_REPO_NAME = &lt;censored&gt;
  [Container] 2017/02/16 22:04:34 Processing builtin environment variables
  [Container] 2017/02/16 22:04:34 Moving to directory /tmp/src733484785/src
  [Container] 2017/02/16 22:04:34 Preparing to copy artifacts
  [Container] 2017/02/16 22:04:34 No artifact files specified
  </code></pre>
  
  <p>CodeBuild sees my commands, but it doesn't run them!  The build is marked as successful.  Does anyone know what I've done wrong here?</p>
  
  <p>UPDATE: I needed to change <code>post-build</code> to <code>post_build</code>.  The build now pulls the maven image to build the jar, and then docker builds the image.  This way, my jar doesn't contain the source code, and the image doesn't contain maven and the jdk.  This is my working <code>buildspec.yml</code>:</p>
  
  <pre><code>version: 0.1
  
  phases:
    pre_build:
      commands:
        - echo Logging in to Amazon ECR...
        - $(aws ecr get-login --region $AWS_DEFAULT_REGION)
        - echo Pulling maven image...
        - docker pull maven:3.3-jdk-8
    build:
      commands:
        - echo Build started on `date`
        - echo Building jar...
        - docker run -i --rm -w /opt/maven -v $PWD:/opt/maven -v $HOME/.m2:/root/.m2 maven:3.3-jdk-8 mvn clean install
        - echo Building Docker Image...
        - docker build -t $IMAGE_REPO_NAME .
        - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
    post_build:
      commands:
        - echo Build completed on `date`
        - echo Pushing Docker image...
        - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
  </code></pre>