When you have an Elastic Beanstalk environment, it is easy to upgrade a minor version by going into the console and clicking Change.

But can you upgrade, for example, this version of PHP 7.4 into PHP version 8? It turns out there is a handy command in aws-cli that can do this in one go:

aws elasticbeanstalk update-environment --solution-stack-name "64bit Amazon Linux 2 v3.3.12 running PHP 8.0" --environment-id "e-XXXXXXXXXX" --region "us-east-1"

In the above command there is three things to consider:

  • Solution Stack Name: can be found in aws documentation here.
  • Environment ID (e-XXXXXXXXX): can be found by going into the AWS console > Elastic Beanstalk > Environments > Go into environment to update, you can get the Environment ID from the url as a param environmentId=e-XXXXXXXXXX
  • Region: the region the environment is in.

Once you run the command you get the following response:

{
    "Tier": {
        "Name": "WebServer",
        "Version": "1.0",
        "Type": "Standard"
    },
    "EnvironmentName": "ENVIRONMENT_NAME",
    "EndpointURL": "ENVIRONMENT_URL",
    "Status": "Updating",
    "VersionLabel": "VERSION",
    "CNAME": "ENVIRONMENT_CNAME",
    "AbortableOperationInProgress": true,
    "SolutionStackName": "CURRENT_VERSION",
    "ApplicationName": "APPLICATION_NAME",
    "Description": "ENVIRONMENT_DESCRIPTION",
    "EnvironmentId": "ENVIRONMENT_ID",
    "PlatformArn": "PLATFORM_ARN",
    "DateUpdated": "2022-04-14T15:15:17.496Z",
    "EnvironmentArn": "ENVIRONMENT_ARN",
    "DateCreated": "2021-05-13T14:34:51.122Z",
    "Health": "Grey"
}

The environment will go into a transition:

And after a couple of minutes it should go back to green in the new version.

Leave a Reply

Your email address will not be published. Required fields are marked *