Difference between revisions of "AWS/User data"
< AWS
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
*Windows 2016< - ec2launch | *Windows 2016< - ec2launch | ||
= | = Retrieve use_data script = | ||
#<code>PS1 C:> Invoke-RestMethod -uri http://169.254.169.254/latest/user-data</code> ; never worked | |||
#in a console, select instance, Instance Settings > View/Change User Data | |||
= EC2Launch = | |||
Configuration file | Configuration file | ||
<source> | <source> | ||
Line 45: | Line 49: | ||
</powershell> | </powershell> | ||
</source> | </source> | ||
= Resources = | |||
*[https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html Running commands at launch] | |||
*[https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-instances.html Configure instances]EC2Launch and EC2Config |
Revision as of 00:26, 19 May 2019
User_data scripts have many derivatives depends on operating system, and following do parse the script:
- Linux - uses cloud_init
- Windows 2012 - ec2config
- Windows 2016< - ec2launch
Retrieve use_data script
PS1 C:> Invoke-RestMethod -uri http://169.254.169.254/latest/user-data
; never worked- in a console, select instance, Instance Settings > View/Change User Data
EC2Launch
Configuration file
C:\ProgramData\Amazon\EC2-Windows\Launch\Config\LaunchConfig.json
Log files are in C:\ProgramData\Amazon\EC2-Windows\Launch\Log
*Ec2Launch.txt - the app itself logs *UserDataExecution.txt - contains parsing details and the script output *WallpaperSetup.txt -
Script parsing sections:
<script>cmd://batch commands</script> #always is parsed 1st <powershell></powershell> #2nd <persist>true</persist> #by default is false, true will run on each reboot <runAsLocalSystem></runAsLocalSystem> <powershellArguments></powershellArguments>
Example user_data.tpl script that will initialise 1st attached volume
<powershell> $file = @" select disk 1 attributes disk clear readonly online disk convert mbr create partition primary format quick fs=ntfs label="log" assign letter="d" "@ Set-Content -Path ${env:TEMP}\diskpart -Value $file diskpart.exe /s ${env:TEMP}\diskpart </powershell>
Resources
- Running commands at launch
- Configure instancesEC2Launch and EC2Config