문제

I'm having a lot of trouble trying to get a Cloud Formation template running correctly with auto scaling. I have the following resource:

"LaunchConfig" : {
  "Type" : "AWS::AutoScaling::LaunchConfiguration",
  "Properties" : {
    "KeyName" : { "Fn::FindInMap" : [ "EnvironmentToKeyName", { "Ref" : "Environment" }, "KeyName" ] },
    "ImageId" : { "Fn::FindInMap" : [ "AWSRegionToAMI", { "Ref" : "AWS::Region" }, "AMI" ] },
    "SecurityGroups" : [ "neat_spi" ],
    "InstanceType" : { "Ref" : "InstanceType" },
    "UserData" : { "Fn::Base64" : {
        "Fn::Join" : ["", [ "<script>", "call c:\\chef\\boot.bat", { "Ref" : "Environment" }, "</script>"]]
      }
    }
  }
}

But it doesn't look like this script is running at all when the machine is started. How do I make sure it runs? Or how do I figure out why it isn't running?

I can't find any logging anywhere on how to see if this was run or not.

도움이 되었습니까?

해결책 3

After the VM boots, you can run remote commands on it with WinRM. Here's an example client:

https://github.com/WinRb/WinRM

Make sure WinRM is enabled in your Windows AMI and that the correct port is open in the security group.

다른 팁

Couple of things to look for...

  1. Verify the cfn tools are installed
  2. Look in the c:\cfn subdirectory - there's a path called logs floating around there somewhere - review that.
  3. Look under program files\amazon\ec2tools - there's a log directory in there. Check to make sure that it's running the script
  4. In the directory above there's a folder called scripts - you should see something that looks like userdata.bat - try running that to confirm it works.

Troubleshooting CloudFormation and Userdata is time consuming - and can be costly - because you get billed for an hour every time you start and stop the instance. Something that works to great advantage for Amazon. (Bring on per minute pricing please)

I had a heck of a time getting the scripts to run on my AMI as well. It worked when I used a standard Amazon AMI, but it didn't work with my custom build AMIs.

I then found this link Create a Standard Amazon Machine Image Using Sysprep.

To summarize, I

  1. I made sure termination protection was turned on (this caused me to lose all my work once)
  2. Launched into a new Windows instance
  3. I customized the instance by doing things like installing windows features I needed and installing an .MSI that I needed.
  4. I turned on Windows Updates and cleared the recycle bin
  5. I ran EC2ConfigService Settings from Start -> All Programs
  6. I checked "Enable UserData execution for next service start (automatically enabled at SysPrep) eg. <script></script> or <powershell></powershell>" on the General tab.
  7. Make sure you set a proper password policy on the Image tab. I chose Random.
  8. Click Apply and then click Shutdown with SysPrep
  9. When the EC2 instance is finally stopped, you can create an image from the AWS console.

This new AMI was able to run my UserData scripts properly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top