Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging user-data Script Output on EC2 Instances on windows

Tags:

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.

like image 265
max Avatar asked Dec 06 '13 20:12

max


People also ask

Where is the user data script in EC2 instance runs?

When a user data script is processed, it is copied to and run from /var/lib/cloud/instances/ instance-id / . The script is not deleted after it is run. Be sure to delete the user data scripts from /var/lib/cloud/instances/ instance-id / before you create an AMI from the instance.

How do I log into Windows EC2 instance?

Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, select Instances. Select the instance and then choose Connect. On the Connect to instance page, choose the RDP client tab, and then choose Get password.


1 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.

like image 128
user1169420 Avatar answered Oct 23 '22 14:10

user1169420