How to Solve AWS Elastic Beanstalk Deployment Error: “Failed to deploy application”?

I’m encountering persistent deployment errors on AWS Elastic Beanstalk and codePipeline, and I need some assistance to diagnose and resolve the issue. The error message I receive is:

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-0aa5817c1885fa11e'. Aborting the operation.

Here are the details of my setup and what I have tried so far:

Environment Details:

  • Platform: AWS Elastic Beanstalk

  • Instance Type: Amazon Linux 2

  • Python Version: 3.11

Deployment Scripts:

buildspec.yml:

version: 0.2

phases:
  install:
    runtime-versions:
      python: 3.11
    commands:
      - echo Installing dependencies...
      - pip install --upgrade pip
      - pip install -r requirements.txt

  pre_build:
    commands:
      - echo Pre-build phase...

  build:
    commands:
      - echo Build phase...

  post_build:
    commands:
      - echo Post-build phase...

artifacts:
  files:
    - '**/*'
  base-directory: .

.ebextensions/install_firefox.config:

packages:
  yum:
    python3-devel: []
    libX11-devel: []
    libXtst-devel: []
    libXScrnSaver: []
    alsa-lib: []
    xorg-x11-server-Xvfb: []
    libxkbcommon-x11: []
    at-spi2-core: []
    google-noto-cjk-fonts-common: []
    google-noto-sans-cjk-ttc-fonts: []

commands:
  01_install_dependencies:
    command: yum install -y wget bzip2

  02_cleanup_previous_files:
    command: |
      rm -f /opt/firefox.tar.bz2
      rm -f /opt/geckodriver.tar.gz

  03_download_firefox:
    command: |
      wget -O /opt/firefox.tar.bz2 "https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US"
      tar -xjf /opt/firefox.tar.bz2 -C /opt/
      chmod +x /opt/firefox/firefox
      ln -sf /opt/firefox/firefox /usr/bin/firefox

  04_download_geckodriver:
    command: |
      wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz -O /opt/geckodriver.tar.gz
      tar -xzf /opt/geckodriver.tar.gz -C /opt/
      mv /opt/geckodriver /usr/local/bin/geckodriver
      chmod +x /usr/local/bin/geckodriver
      ln -sf /usr/local/bin/geckodriver /usr/bin/geckodriver

  05_install_firefox:
    command: yum install -y xorg-x11-server-Xvfb

  06_configure_xvfb:
    command: |
      Xvfb :99 -screen 0 1920x1080x24 &
      export DISPLAY=:99

  07_configure_firefox_options:
    command: |
      mkdir -p /etc/firefox
      echo "FIREFOX_ARGS=--headless" >> /etc/firefox/default

Selenium Helper Script:

import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.firefox.service import Service
from selenium.common.exceptions import WebDriverException

def init_driver():
    try:
        options = webdriver.FirefoxOptions()
        options.headless = True
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-dev-shm-usage')

        driver_path = '/usr/local/bin/geckodriver'
        service = Service(driver_path)
        driver = webdriver.Firefox(service=service, options=options)
        return driver

    except WebDriverException as e:
        print(f"WebDriverException occurred...: {e}")
        return None
    except Exception as e:
        print(f"Error occurred...: {e}")
        return None

def get_full_page_html(driver, base_url):
    if driver is None:
        return None

    driver.get(base_url)
    
    try:
        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located((By.CSS_SELECTOR, "body"))
        )
        print(f"Successfully navigated to {base_url}")

    except TimeoutException as error:
        print(f"Error occurred while waiting for the page to load: {error}")
        return None
    except WebDriverException as error:
        print(f"WebDriverException occurred while loading the page: {error}")
        return None
    
    time.sleep(2)
    page_source = driver.page_source
    return page_source

Additional Context:

  • I have attempted to ensure idempotent scripts and have included cleanup commands to remove previous files before downloading new ones.

  • I removed all application versions from Elastic Beanstalk, removed the entire Elastic Beanstalk application, and recreated a new EB application.

  • I tried deploying just a basic sample Flask application.

  • I have checked CloudWatch logs and the failing instance logs but couldn’t find a specific cause.

  • From my research, I found that reusing the same ZIP file name could cause such issues but it also not working

  • This issue started occurring when I began working with Selenium. Prior to that, deployments were consistently successful.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật