Preparations
Install and configure Alibaba Cloud CLI for the Elastic Compute Service (ECS) instances on which you want to update images.
wget https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.60-amd64.tgz
tar -zxvf aliyun-cli-linux-3.0.60-amd64.tgz
mv aliyun /usr/local/bin

Write a Packer template. In this example, a Packer template is written to update images. You can configure the parameters based on your business requirements.
{
"builders": [
{
"type": "alicloud-ecs",
"region": "cn-hangzhou",
"profile": "default",
"image_name": "OOS_packer_update_image",
"source_image": "<source_image_id>",
"ssh_username": "user_1",
"instance_type": "ecs.g6.xlarge",
"io_optimized": "true",
"system_disk_mapping": {
"disk_category": "cloud_essd",
"disk_size": 40
},
"internet_charge_type": "PayByTraffic",
"image_force_delete": "true"
}
],
"provisioners": [
{
"type": "shell",
"inline": ["sleep 30", "yum install redis.x86_64 -y"]
}
]
}
Log on to the Object Storage Service (OSS) console and upload the Packer template to an OSS bucket.

Execute the Packer template
1. Log on to the CloudOps Orchestration Service (OOS) console. In the left-side navigation pane, choose Automated Task > Public Template. On the page that appears, search for the ACS-ECS-RunPacker template and click Create Execution.

2. In the Basic Information step, configure the parameters and click Next Step: Parameter Settings.

3. In the Select ECS Instance section of the Parameter Settings step, select the instances for which you have configured Alibaba Cloud CLI. The selected instances must be assigned a RAM role that has the read permissions on OSS. Then, click Next Step: OK. For more information about how to assign a RAM role to instances, see the "Scenario 2" section of the Download files to multiple instances at a time topic.

4. Click Create.

5. View the execution result on the execution details page. The process of updating images by using Packer is time-consuming. Wait until the execution is complete.

Process description
The following code shows how Packer updates ECS images:
==> alicloud-ecs: Prevalidating source region and copied regions...
==> alicloud-ecs: Force delete flag found, skipping prevalidating image name.
alicloud-ecs: Found image ID: m-bp12i2mrva8etqnugcxn
==> alicloud-ecs: Creating temporary keypair: packer_5f90fbd1-27f5-3f5f-a7c3-9470b51183e2
==> alicloud-ecs: Creating vpc...
alicloud-ecs: Created vpc: vpc-bp1m0tkybn06u04v32ryn
==> alicloud-ecs: Creating vswitch...
alicloud-ecs: Created vswitch: vsw-bp1f67vlm6h72osjr2le5
==> alicloud-ecs: Creating security group...
alicloud-ecs: Created security group: sg-bp11tp7gcrgwtqlq9nhf
==> alicloud-ecs: Creating instance...
alicloud-ecs: Created instance: i-bp16p08isghg3hbcwijx
==> alicloud-ecs: Allocating eip...
alicloud-ecs: Allocated eip: 47.97.112.43
alicloud-ecs: Attach keypair packer_5f90fbd1-27f5-3f5f-a7c3-9470b51183e2 to instance: i-bp16p08isghg3hbcwijx
==> alicloud-ecs: Starting instance: i-bp16p08isghg3hbcwijx
==> alicloud-ecs: Using ssh communicator to connect: 47.97.112.43
==> alicloud-ecs: Waiting for SSH to become available...
==> alicloud-ecs: Connected to SSH!
==> alicloud-ecs: Provisioning with shell script: /tmp/packer-shell177009608
alicloud-ecs: CentOS-8 - AppStream 517 kB/s | 4.3 kB 00:00
alicloud-ecs: CentOS-8 - AppStream 38 MB/s | 5.8 MB 00:00
alicloud-ecs: CentOS-8 - Base 498 kB/s | 3.9 kB 00:00
alicloud-ecs: CentOS-8 - Base 28 MB/s | 2.2 MB 00:00
alicloud-ecs: CentOS-8 - Extras 196 kB/s | 1.5 kB 00:00
alicloud-ecs: CentOS-8 - Extras 247 kB/s | 8.1 kB 00:00
alicloud-ecs: Extra Packages for Enterprise Linux 8 - x86_64 614 kB/s | 4.7 kB 00:00
alicloud-ecs: Extra Packages for Enterprise Linux 8 - x86_64 80 MB/s | 8.1 MB 00:00
alicloud-ecs: Dependencies resolved.
alicloud-ecs: ================================================================================
alicloud-ecs: Package Arch Version Repository Size
alicloud-ecs: ================================================================================
alicloud-ecs: Installing:
alicloud-ecs: redis x86_64 5.0.3-2.module_el8.2.0+318+3d7e67ea AppStream 925 k
alicloud-ecs: Enabling module streams:
alicloud-ecs: redis 5
alicloud-ecs:
alicloud-ecs: Transaction Summary
alicloud-ecs: ================================================================================
alicloud-ecs: Install 1 Package
alicloud-ecs:
alicloud-ecs: Total download size: 925 k
alicloud-ecs: Installed size: 3.2 M
alicloud-ecs: Downloading Packages:
alicloud-ecs: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_6 11 MB/s | 925 kB 00:00
alicloud-ecs: --------------------------------------------------------------------------------
alicloud-ecs: Total 11 MB/s | 925 kB 00:00
alicloud-ecs: Running transaction check
alicloud-ecs: Transaction check succeeded.
alicloud-ecs: Running transaction test
alicloud-ecs: Transaction test succeeded.
alicloud-ecs: Running transaction
alicloud-ecs: Preparing : 1/1
alicloud-ecs: Running scriptlet: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
alicloud-ecs: Installing : redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
alicloud-ecs: Running scriptlet: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
alicloud-ecs: Verifying : redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64 1/1
alicloud-ecs:
alicloud-ecs: Installed:
alicloud-ecs: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64
alicloud-ecs:
alicloud-ecs: Complete!
==> alicloud-ecs: Stopping instance: i-bp16p08isghg3hbcwijx
==> alicloud-ecs: Waiting instance stopped: i-bp16p08isghg3hbcwijx
==> alicloud-ecs: Deleting duplicated image and snapshot in cn-hangzhou: OOS_packer_test2
==> alicloud-ecs: Creating image: OOS_packer_test
alicloud-ecs: Detach keypair packer_5f90fbd1-27f5-3f5f-a7c3-9470b51183e2 from instance: i-bp16p08isghg3hbcwijx
==> alicloud-ecs: Cleaning up 'EIP'
==> alicloud-ecs: Cleaning up 'instance'
==> alicloud-ecs: Cleaning up 'security group'
==> alicloud-ecs: Cleaning up 'vSwitch'
==> alicloud-ecs: Cleaning up 'VPC'
==> alicloud-ecs: Deleting temporary keypair...
Build 'alicloud-ecs' finished after 6 minutes 28 seconds.
==> Wait completed after 6 minutes 28 seconds
==> Builds finished. The artifacts of successful builds are:
--> alicloud-ecs: Alicloud images were created:
cn-hangzhou: m-bp1ah9sq4uzj3yfi62il