Logging AWS EC2 UserData script output on Windows

Viewed 26029

I'm trying to get the EC2 UserData script logs and direct them to system logs on Windows.

On Linux, someone already found out the solution (http://alestic.com/2010/12/ec2-user-data-output). Basically you'd tee /var/log/user-data.log to system logs.

I need to know how to do it for Windows instances. I could not find any user-data.log on my windows instance.

5 Answers

Several of the paths in the answers to this question are out of date as of July 2019. There is no longer any C:\Program Files\Amazon\Ec2ConfigService nor C:\CFN (for me atleast but I'm not using CFN to provision if that matters)

At first I thought the C:\ProgramData\Amazon\ location was also out of date but I forgot that ProgramData is hidden on windows and by default hidden files are not shown. Remember how every time you install windows you have to set the selection to "show hidden files"? I forgot about that here.

So the windows user data logs are in C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log

Also if it helps, the Userdata script itself (post-any-provisioning-templating, as presented to the instance) is in C:\Windows\Temp\UserScript.ps1

But I'd like to second tarvinder91's recommendation of using the powershell function "Start-Transcript" to trivially create your own logs. You can set a custom path and -Append like Start-Transcript -Path "C:\UserData.log" -Append at the beginning of your script. This way you can control where the log goes and not worry about how the AMI is configured to store logs.

You don't really have to depend on the standard logs for any cloud/service. Just use start-transcript in your powershell code in the start. It will store all the logs for you generally in C:\Users\Administrators\Documents if this command is run from Administrator profile or at other locations as per the user profile running the script.

Related