32

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.

7 Answers 7

22

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.

3
  • Doc ref
    – Efren
    Commented Apr 30, 2020 at 2:04
  • Saved my day! I confirm this works.
    – Souad
    Commented Jun 24, 2022 at 9:54
  • 1
    IF You can't find the user data logs The log files for EC2Launch, EC2Launch v2, and EC2Config contain the output from the standard output and standard error streams. You can access the log files at the following locations: EC2Launch v2: C:\ProgramData\Amazon\EC2Launch\log\agent.log EC2Launch: C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log EC2Config: C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.tx Note: By default, C:\ProgramData is a hidden folder.
    – nailed IT
    Commented Nov 23, 2023 at 10:51
13

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
1
  • The file that the OP is looking for is UserdataExecution.log.
    – alex
    Commented Aug 9, 2022 at 19:40
8

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

7

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.

1
  • This is the answer that helped me. Although I did find C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log. This is a good powershell trick to know in general anyway. Thanks Commented Jul 1, 2019 at 18:36
4

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:

enter image description here

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?

1

In our case the powershell command outputs were only logged in C:\WINDOWS\system32\config\systemprofile\AppData\Local\Temp\ path

0

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.

2
  • 3
    It'd be useful to others to include where that log file is located. Commented Sep 4, 2014 at 23:15
  • 4
    You can get the logging information from the user-data scripts in the C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.txt file. Commented Dec 11, 2014 at 14:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.