I'm trying to execute a startup script on a Windows EC2 instance (g4ad.large).
I'm using the agent-config.yml
configuration file for EC2Launch v2, and trying to use the executeScript task.
Here's my entire agent-config.yml
:
version: 1.0
config:
- stage: boot
tasks:
- task: extendRootPartition
- stage: preReady
tasks:
- task: activateWindows
inputs:
activation:
type: amazon
- task: setDnsSuffix
inputs:
suffixes:
- $REGION.ec2-utilities.amazonaws.com
- task: setAdminAccount
inputs:
password:
type: random
- task: setWallpaper
inputs:
path: C:\ProgramData\Amazon\EC2Launch\wallpaper\Ec2Wallpaper.jpg
attributes:
- hostName
- instanceId
- privateIpAddress
- publicIpAddress
- instanceSize
- availabilityZone
- architecture
- memory
- network
- stage: postReady
tasks:
- task: startSsm
- task: executeScript
inputs:
- frequency: always
type: powershell
runAs: admin
content: >-
Write-Host "powershell::admin::whoami"
whoami
- frequency: always
type: powershell
runAs: localSystem
content: >-
Write-Host "powershell::localSystem::whoami"
whoami
- frequency: always
type: batch
runAs: admin
content: >-
echo "batch::admin::whoami"
whoami
- frequency: always
type: batch
runAs: localSystem
content: >-
echo "batch::localSystem::whoami"
whoami
After restarting the instance, the scripts above are all being run, but agent.log
shows that they all run with system user: Info: Run as: localSystem
.
Looking at the output of scripts, they all list the whoami value as nt authority\system
.
I'm trying to run a script using the Administrator user, but runAs: admin
seems to have no affect...
Any help would be greatly appreciated - thanks!!