User-data scripts is not running on my custom AMI, but working in standard Amazon linux

后端 未结 11 1361
南方客
南方客 2020-12-08 02:15

I searched a lot of topic about \"user-data script is not working\" in these few days, but until now, I haven\'t gotten any idea about my case yet, please help me to figure

11条回答
  •  不思量自难忘°
    2020-12-08 02:36

    User_data is run only at the first start up. As your image is a custom one, I suppose it have already been started once and so user_data is desactivated.

    For windows, it can be done by checking a box in Ec2 Services Properties. I'm looking at the moment how to do that in an automated way at the end of the custom image creation.

    For linux, I suppose the mechanism is the same, and user_data needs to be re-activated on your custom image.

    The #cloud-boothook make it works because it changes the script from a user_data mechanism to a cloud-boothook one that runs on each start.


    EDIT :

    Here is the code to reactivate start on windows using powershell:

    $configFile = "C:\\Program Files\\Amazon\\Ec2ConfigService\\Settings\\Config.xml"
    [xml] $xdoc = get-content $configFile
    $xdoc.SelectNodes("//Plugin") |?{ $_.Name -eq "Ec2HandleUserData"} |%{ $_.State = "Enabled" }
    $xdoc.SelectNodes("//Plugin") |?{ $_.Name -eq "Ec2SetComputerName"} |%{ $_.State = "Enabled" }
    $xdoc.OuterXml | Out-File -Encoding UTF8 $configFile
    
    $configFile = "C:\\Program Files\\Amazon\\Ec2ConfigService\\Settings\\BundleConfig.xml"
    [xml] $xdoc = get-content $configFile
    $xdoc.SelectNodes("//Property") |?{ $_.Name -eq "AutoSysprep"} |%{ $_.Value = "Yes" }
    $xdoc.OuterXml | Out-File -Encoding UTF8 $configFile
    

    (I know the question focus linux, but it could help others ...)

提交回复
热议问题