I have a simple user data script that is executed on an EC2 instance part of an ECS cluster. Recently, I added the bottom section which tries to map a network drive (FSx) storage to the instance:
user data ps1 script:
<powershell>
Import-Module ECSTools
[Environment]::SetEnvironmentVariable("ECS_ENABLE_AWSLOGS_EXECUTIONROLE_OVERRIDE", $TRUE, "Machine")
Initialize-ECSAgent -Cluster "${cluster_name}" -EnableTaskIAMRole -LoggingDrivers '["json-file","awslogs"]' -EnableTaskENI
echo "map the FSx storage drive"
net use D: "\\server.mydomain\share" "/USER:mydomain\myuser" "mypassword" "/PERSISTENT:YES"
</powershell>
The problem is that when the EC2 instance launches, the "D" drive is not mapped at all when listing all drives in the system using gdr -PSProvider 'FileSystem'
command:
That said, when I execute the user data script manually (i.e. remote connect to the instance), it works and I can see the D:/ drive being mapped:
powershell C:\Windows\TEMP\UserScript.ps1
I don't see any errors in the C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log
file either. I see the echo
text from my script that is not followed by any errors:
...
2021-12-15T12:32:05Z - [INFO]:ScheduledTask Initialize-ECSHostReboot created.
2021-12-15T12:32:05Z - [INFO]:Task IAM role is enabled. Changing AmazonECS service startup to Manual.
map the FSx storage drive
The command completed successfully.
2021/12/15 12:32:06Z: Userdata execution done
What am I missing here?