You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
User data
Setting custom data
Copy page
Download PDF
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.​
tip​
For sample scripts in different formats, please refer to Sample custom data scripts.​
​
Operating system​
Script format​
Linux​
  • Shell​
  • Cloud Config​
Windows​
  • Batch​
  • PowerShell​
​
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.​
​
Step 3: Verify the content and result passed to the instance​
​
Linux instance
Windows instance
​
  1. View the content passed in from instance metadata.​
  • Run the following command to view the instance custom data as a root user. If the output matches the content passed in from Step 2, then the custom data has been successfully passed in the instance.​
  • ​
    curl http://100.96.0.96/latest/user_data​
    ​
  • ​alt​​
  1. Run the following command to view the result of the instance custom data.​
  • The result depends on the content of the custom data. This topic takes writing specified content to the specified file userdata_test.txt as an example.​
  • ​
    cat userdata_test.txt​
    ​
  • ​alt​​
​
Custom data sample scripts​
We recommend using the following script formats to set custom data. For more script formats, please refer to the official cloudbase-init documentation.​
​
Linux
Windows
​
  • Shell​
  • Starts with#!, such as#!/bin/bash, with no spaces at the beginning. The sample script is as follows:​
  • ​
    #!/bin/bash​
    echo "Hello World !" > /root/userdata_test.txt​
    ​
  • Cloud Config​
  • Starts with#cloud-config, with no spaces at the beginning. The sample script is as follows:​
  • ​
    #cloud-config​
    bootcmd:​
    - echo "Hello World !" > /root/userdata_test.txt​
    ​
​
Related documents​
Last updated: 2026.10.14 17:33:22