The application publishing feature of Auto Scaling lets you continuously deploy business applications to Elastic Compute Service (ECS) instances in a scaling group. This feature automates the application publishing process and integrates with Auto Scaling lifecycle hooks to enable automatic publishing and graceful shutdowns.
Overview
The application publishing feature of Auto Scaling (ESS) encapsulates application source files and start and stop scripts into a deployment. This deployment is then published to instances in a scaling group through a standard process.
Supported deployment types
You can choose a deployment type based on where your application source files are stored:
Type | Description | Scenarios |
OSS file | Application files, such as JAR or ZIP packages, are stored in OSS. During publishing, the files are automatically downloaded and the scripts are executed. | Traditional application deployments, such as Java applications. |
ECS image | The application is pre-installed in an ECS image. During publishing, the system disk of the instance is replaced. | Applications that require fast startup or have complex environments. |
Docker image | The application image is stored in Container Registry (ACR). During publishing, the image is automatically pulled and the container is started. | Containerized application deployments. |
Command execution only | No source file is specified. Only a shell script is executed. | Flexible scripted deployments or for using third-party sources. |
Release capabilities
Release Mode: Supports full release to publish to all instances and canary release to publish to specific instances for validation.
Batch control: You can set release batches and configure pauses between them to reduce risks during a release.
Auto Scaling integration:
Automatic publishing on scale-out: New instances created during a scale-out automatically deploy the latest application version to ensure version consistency.
Graceful shutdown on scale-in: Before a scale-in, a stop script is executed to ensure that business processes are complete before the instance is released.
Limitations
Operating system: Only Linux ECS instances are supported.
Scripting language: Only shell scripts are supported for start and stop scripts.
Deployment flow: The deployment flow follows the Stop-before-start principle. For each deployment, the stop script is executed first to ensure that the application from the previous deployment is stopped. Then, the start script is executed.
Data risk: When you use the ECS image deployment type, the system disk of the instance is replaced. You must back up important data beforehand.
Create a deployment
-
Log on to the Auto Scaling console.
In the left-side navigation pane, click Scaling Groups.
In the top navigation bar, select the region where Auto Scaling is activated.
Click a Scaling Group ID to go to the details page of the scaling group. On the App Release tab, choose .
Select and configure a deployment type based on your scenario.
OSS file
Use this type when your application packages, such as JAR, WAR, or ZIP files, are stored in OSS. During publishing, the system automatically downloads the files to a specified working directory. It then executes the stop script to stop the previous application version, if any, before it executes the start script to launch the new application.
Configuration items:
OSS Information: Set the OSS RegionId and OSS Bucket. In the ObjectName field, enter the path to the file in the bucket, such as
apps/sample-spring-1.0-SNAPSHOT.jar.Download over internal network: If your ECS instance and OSS bucket are in the same region, you can enable this option to increase download speed.
Start/Stop Script Example:
applicationStartScript:
start_application() { set -e yum install -y maven-3.5.4 java -jar ./sample-spring-1.0-SNAPSHOT.jar & } start_applicationapplicationStopScript:
ImportantIf you do not need to perform any stop operations, you can leave the stop script empty. The stop script is skipped during deployment.
### Stop the application (if any) stop_application() { PID=$(ps -ef | grep "sample-spring-1.0-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}') if [ -n "$PID" ]; then kill -9 $PID fi } stop_application
ECS image
Use this type for applications that have complex environments or require fast startup. During publishing, the system replaces the system disks of the instances in the scaling group with the specified image.
If you select ECS image as the deployment type, click Add and select an image from the same region as your scaling group.
Configuration items:
Region: Select the same region as the scaling group.
Image ID: Select a custom image that contains the deployed application and is in the same region as the scaling group.
ImportantECS image deployments do not support Application start/stop scripts. To start the application automatically, you can configure the application to start on boot or manually configure a lifecycle hook.
Docker image
Use this type for containerized applications. During publishing, the system automatically pulls the image from ACR. It then executes the stop script to stop the previous container version, if any, before it executes the start script to launch the new container.
ImportantOnly Docker images from Container Registry (ACR) Enterprise Edition are supported. For images from ACR Personal Edition or third-party image repositories, use the Command execution only deployment type.
Configuration items:
Docker Image Information: You can set Container Registry Region, Container Registry Instance ID, Namespace, Repository Name, and Image Version.
Pull over internal network: To pull the image over an internal network, make sure your image repository and ECS instance are in the same VPC. For more information, see Configure access control for a VPC.
Startup and Shutdown Script:
Application start script:
ImportantMake sure Docker is installed on the target machine.
During publishing, the Docker image is automatically pulled to the ECS instance before the script is executed. You do not need to include image pull operations in the script.
### During publishing, the Docker image is automatically pulled to the ECS instance. You can start the container directly. ### Start the current version of the container ### When using, replace <image_name> with the actual image address start_application() { image_name="<image_name>" container_name="my-container" docker run -d -p 8080:8080 --name ${container_name} ${image_name} } start_applicationApplication stop script:
ImportantIf you do not need to perform any stop operations, you can leave the stop script empty. The stop script is skipped during deployment.
stop_application() { # Find the container by name. If it exists, delete it. container_name="my-container" container_id=$(docker ps -aq -f name=${container_name}) if [ -n "$container_id" ]; then docker rm -f $container_id fi } stop_application
Command execution only
Use this type for deployments that require only a shell script and no specific source files, such as downloading code from a third-party source. During publishing, the system executes the stop script to stop the previous application version, if any, before it executes the start script to launch the new application.
Configuration items: You do not need to configure a deployment source. You only need to specify the Working Directory.
Start/Stop Script Example (pulling a public image):
Application start script:
### Start the current version of the application start_application() { repo="<repo>" image="<image>" container_name="my-container" docker login --username=${username} --password=${password} $repo docker pull $image docker run -d -p 8080:8080 --name $container_name $image } start_applicationApplication stop script:
ImportantIf you do not need to perform any stop operations, you can leave the stop script empty. The stop script is skipped during deployment.
### Stop the container (if any) stop_application() { # Find the container by name and delete it if it exists. container_name="my-container" container_id=$(docker ps -aq -f name=${container_name}) if [ -n "$container_id" ]; then docker rm -f $container_id fi } stop_application
After completing the configuration, click Create and Publish or Create Only.
If you click Create and Publish, you are taken to the Publish Deployment configuration.
Publish Deployment
On the App Release tab, choose .
You can select the DeployRevisionId to publish.
Configure the release policy:
DeployMethod:
Full-scale publishing: Publishes to all instances in the group.
Grayscale publishing: Publish to manually selected instances.
Batch Policy: Set the BatchNumber (for example, 2) and select a Batch Mode (No Pause, Pause After First Batch, or Pause After Each Batch).
Scaling Scenarios: Keep the default settings enabled for whetherStartApplicationWhenScaleOut and whetherStopApplicationWhenScaleIn.
whetherStartApplicationWhenScaleOut: If this option is enabled, the application is automatically published to new ECS instances that are created during a scale-out. A scale-out lifecycle hook is automatically configured during the publishing process.
whetherStopApplicationWhenScaleIn: If this option is enabled, the stop script of the deployment is executed on the ECS instances that are being scaled in before the scale-in is complete. A scale-in lifecycle hook is automatically configured during the publishing process.
Click OK to start publishing. You can view the execution status and output logs by clicking Details in the list.
Apply in production
To ensure stability in your production environment, follow these best practices:
Reduce release risks:
First, use a Grayscale publishing to verify the new version on a small number of instances.
To perform a full release in batches, enable phased release and select First batch pause. After the first batch is published and verified, you can continue with the remaining batches.
Ensure business continuity: Enable whetherStopApplicationWhenScaleIn. Write a stop script for your deployment that waits for requests to finish processing and closes connections to prevent business interruptions during a scale-in.
Ensure version consistency: Enabling whetherStartApplicationWhenScaleOut prevents new instances created by the scaling group from running an outdated application version.
FAQ
Does the application publishing feature support Windows instances?
No, it does not. Only Linux ECS instances are supported.
During the publishing process, will the scaling group still trigger scaling activities?
Yes, it will. The application publishing process does not block scaling activities.
How can I view the logs and results of an application publishing?
After a publishing task starts, you can click the Execution ID in the Deployment Release list and view the execution status and detailed script output logs for each instance.
If a deployment fails, what is the impact on existing instances?
If a script fails to run, the publishing status for that instance is set to Failed. For a phased release with Every batch pause or First batch pause enabled, subsequent batches will not run. This limits the impact. You can verify the deployment on a small number of instances using a Grayscale publishing before a full release.
Where is the execution directory for the application start/stop scripts?
The scripts are executed in the Working Directory that you specify when you create the deployment.