- Documentation
Elastic Compute Service
Elastic Compute Service
User Guide
Instances
Using instance user data and metadata
User data
Setting custom data
User data
Setting custom data
Setting custom data
This topic describes how to set custom data for an ECS instance and verify its effects.
Limits
The custom data for an instance must be encoded in Base64 format, and the data cannot exceed 16KB before Base64 encoding.
tip
You can enter custom data that has not been Base64-encoded in the ECS console. The console will automatically perform Base64 encoding.
Procedure
Step 1: Prepare custom data for the instance
Write a script that complies with specifications based on actual requirements. The recommended script formats vary for instances with different operating systems, as described in the following table.
Step 2: Pass custom data to the instance
Pass in custom data when creating an instance
Modify custom data for an existing instance
tip
After configuring custom data for an instance, this data will be executed when the operating system starts for the first time (including the first startup of the instance and the replacement of the operating system).
When purchasing an instance, in the custom configuration phase, expand "Advanced Options" and enter the custom data for the instance. If the custom data of the instance is encoded in Base64 format, select "The text is encoded in Base64 format". Follow the on-screen instructions step by step to create the instance.
tip
- Before modifying custom data, you must stop the instance. Otherwise, new data cannot be passed in.
- After modifying custom data, as the instance status remains Stopped, you need to manually start the instance.
- After the custom data is modified, whether the new custom data runs when you start the instance depends on the script type and module type, for example:
- Shell scripts: They will not run again, but only run when the operating system starts for the first time.
- Cloud Config scripts: If the configuration objects are modules such as Byobu or Set Passwords, they will not run again. They only run when the operating system starts for the first time.
- Cloud Config scripts: If the configuration object is the Update Etc Hosts module, they will run again every time the instance starts.
- For more characteristics of module types, please refer to the individual modules and their module frequencies in Modules.
- When you modify an existing script, the previous content is displayed in the Custom data pane. By default, the script is not encoded in Base64.
- In the left-side navigation pane, select "Instances & Images > Instances".
- In the top menu bar, select the region and project.
- Click the "··· > Instance settings > Change user data" button in the "Actions" column of the stopped instance.
- Enter new custom data. If the instance custom data has been Base64-encoded, please check the "The text is encoded in base64 format".
- Click "Save" to complete the operation.
Step 3: Verify the content and result passed to the instance
Custom data sample scripts
- Starts with#!, such as#!/bin/bash, with no spaces at the beginning. The sample script is as follows:
- Starts with#cloud-config, with no spaces at the beginning. The sample script is as follows:
- Starts with rem cmd, with no spaces at the beginning. The sample script is as follows:
- Starts with #ps1, with no spaces at the beginning. The sample script is as follows:
Related documents
Last updated: 2026.10.14 17:33:22