Reputation: 10464
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.
Upvotes: 32
Views: 42710
Reputation: 454
In our case the powershell command outputs were only logged in C:\WINDOWS\system32\config\systemprofile\AppData\Local\Temp\
path
Upvotes: 1
Reputation: 5748
I found the main logs file here: C:\ProgramData\Amazon\EC2Launch\log\agent.log
And the actual user data script logs file here under a directory: C:\Windows\System32\config\systemprofile\AppData\Local\Temp\[SCRIPT_AND_LOGS_DIRECTORY]\output.tmp
Where [SCRIPT_AND_LOGS_DIRECTORY]
is the directory name having user data script logs files. (e.g., EC2Launch1685509711
)
I had to check Hidden Items
under Show/hide
section view options on File Explorer to access these. This action is same as showing hidden files and folders.
Reference Screenshot:
My OS specifications are as follows:
Edition: Windows Server 2022 Datacenter (64-bit)
Version: 21H2
OS build: 20348.1607
Reference: How can I troubleshoot running user data scripts to configure my EC2 Windows instance?
Upvotes: 4
Reputation: 830
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.
Upvotes: 23
Reputation: 171
For those who find this and are still looking you can try looking in ProgramData. There are a couple log files in there that give you more info about boot.
C:\ProgramData\Amazon\EC2-Windows\Launch\Log\Ec2Launch.log
C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log
Upvotes: 13
Reputation: 106
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.
Upvotes: 7
Reputation: 942
Have you tried looking in C:\CFN\LOG\cfn-init.log - that is typically where you get CFN user data logs?
There is also useful info in and around
C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.txt
Ref: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-windows-stacks-bootstrapping.html
Upvotes: 8
Reputation: 10464
I found that there is a log file dedicated to the user-data execution and it indicates that an error has occurred but it does not indicate what the errors are; so the solution (until ops-code does something better) is to write you user-data code in a way that it directs its output to a file and that file can be parsed to report the error details or to help with debugging.
Upvotes: 0