Having problem deploying node.js application to AWS EB from gitlab pipelines

I have an existing node.js application hosted on gitlab. I try to use gitlab's ci/cd and creating gitlab-ci.yml. Having 3 stages namely build, test, deploy, the first two actually works but deploying it to the aws elastic beanstalk im getting an error in the pipelines saying...

ERROR: This directory has not been set up with the EB CLI
You must first run "eb init".
ERROR: Job failed: exit code 1

Hope you can help me with my problem :(

this is my sample configuration for my deploy stage:

  deploy_aws:
  stage: deploy
  image: coxauto/aws-ebcli
  script:
    - mkdir ~/.aws
    - touch ~/.aws/config
    - chmod 600 ~/.aws/config
    - echo "[profile eb-cli]" >> ~/.aws/config
    - echo "aws_access_key_id=${AWS_ACCESS_KEY_ID}" >> ~/.aws/config
    - echo "aws_secret_access_key=${AWS_SECRET_ACCESS_KEY}" >> ~/.aws/config
    - git checkout master
    - eb deploy sample-sails-app-dev

the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are declared in my gitlab's ci/cd variables.

1 answer

  • answered 2019-05-15 07:53 Aniket Chopade

    AWS Access and Secret keys are stored in file named credentials. (~/.aws/credentials).

    config file has defaults like AWS region & cli output format (json)

    [default]
    region = us-east-1
    output = json
    

    credentials file have Access & secret id's

    [default]
    aws_access_key_id = xx
    aws_secret_access_key = xxx
    

    So in your deploy script change config directory to credentials

    - echo "aws_access_key_id=${AWS_ACCESS_KEY_ID}" >> ~/.aws/credentials