Logging user-data Script Output on EC2 Instances on windows

max picture max · Dec 6, 2013 · Viewed 17.3k times · Source

I'm trying to get the ec2 "user-data" script logs and direct them to system log 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 log. I need to know how to do it for windows instances please. I could not find any user-data.log on my windows instance.

Answer

user1169420 picture user1169420 · Jul 1, 2019

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.