AWS Elastic Beanstalk error: Failed to deploy application

11,606

Ran into the same issue. The first fix worked for me. Listing down all possible fixes which can resolve this issue:

  1. Reason: some bug with elasticbeanstalk, which is making the multi-stage builder step to fail. AWS logs would show you a message like docker pull requires exactly one argument

Solution: Use unnamed builder. By default, the stages are not named, and you refer to them by their integer number, starting with 0 for the first FROM instruction. Make changes in your docker file as below:

### STAGE 1: Build ###
FROM node:12.7-alpine
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build

### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
EXPOSE 80
COPY --from=0 /usr/src/app/dist /usr/share/nginx/html
  1. Reason: Incase using t2.micro as instance type. npm install command sometimes times out on the t2.micro instance.

Solution: Change the instance type that Elastic Beanstalk is using something other than t2.micro(say t2.small)

  1. If none of the above two fixes work, try changing the COPY line of your Dockerfile as below:

    COPY package*.json ./

As AWS sometimes prefer ./ over '.'

Share:
11,606
Matley
Author by

Matley

Updated on June 07, 2022

Comments

  • Matley
    Matley almost 2 years

    I spent many hours to solve my problem. I use CodePipeline : CodeSource, CodeBuild that produces docker container (code from Bitbucket) and stores the image in ECR.

    In CodeDeploy I want to deploy that image from ECR to Elastic Beanstalk:

    Errors in Elastic Beanstalk:

    Environment health has transitioned from Info to Degraded. Command failed on all instances. Incorrect application version found on all instances. Expected version "Sample Application" (deployment 6). Application update failed 15 seconds ago and took 59 seconds.
    
    During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.
    
    Failed to deploy application.
    
    Unsuccessful command execution on instance id(s) 'i-04df549361597208a'. Aborting the operation.
    

    Another error from EB:

    Incorrect application version "code-pipeline-1586854202535-MyflashcardsBuildOutput-ce0d6cd7-8290-40ad-a95e-9c57162b9ff1" 
    (deployment 9). Expected version "Sample Application" (deployment 8).
    

    Error in CodeDeploy:

    Action execution failed
    Deployment completed, but with errors: During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version. Failed to deploy application. Unsuccessful command execution on instance id(s) 'i-04df539061522208a'. Aborting the operation. [Instance: i-04df549333582208a] Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].
    

    Does anyone know what happens here?

    I use Dockerfile:

    ### STAGE 1: Build ###
    FROM node:12.7-alpine AS build
    WORKDIR /usr/src/app
    COPY package.json ./
    RUN npm install
    COPY . .
    RUN npm run build
    
    ### STAGE 2: Run ###
    FROM nginx:1.17.1-alpine
    EXPOSE 80
    COPY --from=build /usr/src/app/dist /usr/share/nginx/html
    

    and buildspec.yml:

    version: 0.2
    phases:
      pre_build:
        commands:
          - echo Logging in to Amazon ECR...
          - aws --version
          - $(aws ecr get-login --region eu-west-1 --no-include-email)
          - REPOSITORY_URI=176901363719.dkr.ecr.eu-west-1.amazonaws.com/myflashcards
          - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
          - IMAGE_TAG=myflashcards
      build:
        commands:
          - echo Build started on `date`
          - echo Building the Docker image
          - docker build --tag $REPOSITORY_URI:latest .
      post_build:
        commands:
          - echo Build completed on `date`
          - echo Pushing the Docker images...
          - docker push $REPOSITORY_URI:latest
          - echo Writing image definitions file...
          - printf '[{"name":"eagle","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
    #      - echo Deleting old artifacts
    #      - aws s3 sync dist/ s3://$BUCKET_NAME --delete
    artifacts:
      files: imagedefinitions.json
    

    The third step (CodeDeploy) fails:(

  • locrizak
    locrizak almost 3 years
    #2 worked for me. Even though I was deploying a pre built image from ECR, I still had to up the instance type