1
votes

I'm trying to get AWS CodePipeline working with S3 source, CodeBuild and Elastic Beanstalk (nodejs environment)

My problem lies between CodeBuild and Beanstalk.

I have CodeBuild outputting a zip file of the final nodeJS app via the artifacts. Here is my CodeBuild buildspec.yml

version: 0.1

phases:
  install:
    commands:
      - echo Installing Node Modules...
      - npm install -g mocha
      - npm install
  post_build:
    commands:
      - echo Performing Test
      - npm test
      - zip -r app-api.zip .
artifacts:
  files:
    - app-api.zip

When I manually run CodeBuild it successfully puts the zip into S3. When I run CodePipeline it puts the zip on each Elastic Beanstalk instance in /var/app/current as app-api.zip

What I would like is for it to extract app-api.zip as /var/app/current. Just like the manual deploy via the Elastic Beanstalk console interface.

1

1 Answers

9
votes

First, a quick explanation. CodePipeline sends whatever files you specified as artifacts to Elastic Beanstalk. In your case, you are sending app-api.zip

What you probably want to do instead, is to send all the files, but not wrap them in a ZIP.

Let's change your buildspec.yml to not create app-api.zip and instead, send the raw files to CodePipeline.

version: 0.1

phases:
  install:
    commands:
      - echo Installing Node Modules...
      - npm install -g mocha
      - npm install
  post_build:
    commands:
      - echo Performing Test
      - npm test
#     - zip -r app-api.zip . **<< Remove this line**
artifacts:
  files:
    - '**/*'
# Replace artifacts/files with the value shown above