node.jsyamlgithub-actionsamazon-elastic-beanstalkaws-cli

How to use the latest platform version automatically for AWS Elastic Beanstalk in GitHub Actions?


I have a GitHub Actions workflow for deploying my Node.js app to AWS Elastic Beanstalk. Here's the relevant part of my YAML file for this deployment:

- name: Install awsebcli
  uses: sparkplug-app/install-eb-cli-action@v1.1.1

- name: Beanstalk Deploy for app
  run: |
    eb init --platform "64bit Amazon Linux 2023 v6.2.2 running Node.js 20" backend
    eb deploy --modules titan --env-group-suffix=stg
  working-directory: ./app
  env:
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
    AWS_DEFAULT_REGION: eu-west-2

The problem I'm facing is that the platform version (v6.2.2) gets updated every 1-2 months, and then my workflow fails because the version I hardcoded is outdated (e.g., the latest version becomes v6.2.3).

What I'd like to achieve:

  1. Ideally, find a way to specify a command that always uses the latest platform version without needing to update it manually.
  2. Alternatively, query the AWS API to determine the current latest version before running eb init, and then use that version in the command.

I've tried leaving the version unspecified in the eb init command, but that results in errors, as Elastic Beanstalk requires a specific version during initialization.

Is there a way to achieve this, either through eb cli, AWS API, or any other method?


I tried using more generic commands like:

eb init --platform "Node.js 20 running on 64bit Amazon Linux" backend --region eu-west-2

and

eb init --platform "64bit Amazon Linux 2023 running Node.js 20" backend --region eu-west-2

I was hoping that these commands would automatically pick up the latest platform version without specifying a specific version number (like v6.2.2). However, they still failed, requiring me to specify the exact version for the initialization to succeed.


Solution

  • you should have jq and aws-cli installed.

    export PLATFORM=$(aws elasticbeanstalk list-available-solution-stacks | jq -c '.SolutionStacks[]' | grep 'Node.js 20')
    echo $PLATFORM
    "64bit Amazon Linux 2023 v6.2.2 running Node.js 20"
    

    Therefore it would be

    - name: Install awsebcli
      uses: sparkplug-app/install-eb-cli-action@v1.1.1
    
    - name: Beanstalk Deploy for app   run: |
        export PLATFORM=$(aws elasticbeanstalk list-available-solution-stacks | jq -c '.SolutionStacks[]' | grep 'Node.js 20')
        eb init --platform "$PLATFORM" backend
        eb deploy --modules titan --env-group-suffix=stg   working-directory: ./app   env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
        AWS_DEFAULT_REGION: eu-west-2
    

    Although I think it is a bug if "node.js 20 running on 64bit Amazon Linux" is not working.