I have been using AWS elastic beanstalk for a while, but I still think that I do not 100% understand how the application versioning works. Recently I started using Github actions, and sometimes the deployments fail and the environment crashes, always the same error :
Error: Deployment failed: Error: Status: 400. Code: InvalidParameterValue, Message: No Application Version named 'myapp-devel-23075dfd8cf9d3ecab85f5a0a4e77bf403040a36' found.
I started an environment from scratch, and the current version in Elastic Beanstalk is this one: Running version: myapp-devel
This is the job running on github actions:
name: EB deploy to myapp
on:
push:
branches:
- 'myapp-devel'
jobs:
deploy:
runs-on: ubuntu-latest
## Environment variables
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_DEVELOP_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_DEVELOP_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_APPLICATION_NAME: ${{ secrets.AWS_DEVELOP_APPLICATION_4_NAME }}
AWS_ENVIRONMENT_NAME: ${{ secrets.AWS_DEVELOP_ENVIRONMENT_4_NAME }}
steps:
- uses: actions/checkout@v4
- name: Install Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Generate deployment package
## create the zip
run: zip -r deploy-${{ github.sha }}.zip . -x '*.png' -x '.gitignore' -x '/plugins/*/webroot/build/*' -x '*.git/*' -x '*.jpeg' -x 'build/*' -x '*.webp' -x 'config-dev-server' -x '*.JPG' -x '*/node_modules/*' -x '.env_example' -x '.htaccess' -x '/plugins/*/webroot/node_modules/*' -x 'webroot/webpack-updater/*' -x '.dockerignore' -x '.vscode' -x '*.gif' -x 'tmp/*' -x 'webroot/cypress/*' -x 'Dockerfile' -x 'docker-compose.yml' -x '*/files/*' -x 'webroot/tests/*' -x '/webroot/node_modules/*' -x '*.jpg' -x 'webroot/emails/*'
- name: Install EB CLI using pip
run: |
python -m pip install --upgrade pip
pip install awsebcli
- name: Upload package to S3 bucket
run: |
eb init --platform 'PHP 8.2' --region ${{ secrets.AWS_DEFAULT_REGION }} ${{ secrets.AWS_DEVELOP_APPLICATION_4_NAME }}
aws s3 --region ${{ secrets.AWS_DEFAULT_REGION }} cp deploy-${{ github.sha }}.zip s3://github-action/develop/
# - name: Create new ElasticBeanstalk Application Version on region ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# aws elasticbeanstalk create-application-version \
# --application-name ${{ secrets.AWS_DEVELOP_APPLICATION_4_NAME }} \
# --source-bundle S3Bucket="github",S3Key="develop/deploy-${{ github.sha }}.zip" \
# --version-label "myapp-devel-${{ github.sha }}" \
# --description "commit-sha-${{ github.sha }}"
# - name: Deploy new ElasticBeanstalk Application Version
# run: aws elasticbeanstalk update-environment --environment-name ${{ secrets.AWS_DEVELOP_ENVIRONMENT_4_NAME }} --version-label "myapp-devel-${{ github.sha }}"
- name: Deploy myapp-devel to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_DEVELOP_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_DEVELOP_SECRET_ACCESS_KEY }}
application_name: ${{ secrets.AWS_DEVELOP_APPLICATION_4_NAME }}
environment_name: ${{ secrets.AWS_DEVELOP_ENVIRONMENT_4_NAME }}
use_existing_version_if_available: true
## every deployment will be a different application versions
version_label: myapp-devel-${{ github.sha }}
region: ${{ secrets.AWS_DEFAULT_REGION }}
deployment_package: deploy-${{ github.sha }}.zip
- name: elastic benstalk logs
run: |
eb logs
What I should add to the version_label parameter? A different hash with each deployment? I also tried to add always the same label "myapp-devel" (without the ${{ github.sha }}), but I still get the same error, that's why I do not understand what I am doing wrong.
I think you can debug this by:
Log in to the AWS Management Console and navigate to Elastic Beanstalk. Go to your environment, and in the "Versions" section, verify that the application version with the specified label (
myapp-devel-${{ github.sha }}) exists.Uncomment the section in your workflow that creates a new Elastic Beanstalk Application Version manually using the AWS CLI. After uncommenting, make sure to provide a unique version label for each deployment. You can use the same approach as before: