Modify user data per instance
Instance => Operations => Instance Settings => Edit User Data
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
/bin/echo "Hello World" >> /tmp/testfile.txt
--//--
- [scripts-user, always]: Execute this script again after reboot
/bin/echo "Hello World" >> /tmp/testfile.txt : This part can be replaced with your own script code
Note: This script task is executed by the root user , so you need to pay attention to the path of ~ in the shell code
reference:
Running User Data After EC2 Instance Initial Launch | AWS re:Post
Run commands on your Linux instance at launch - Amazon Elastic Compute Cloud