1

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: enter image description here

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

enter image description here

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?

Georgi Koemdzhiev
  • 11,421
  • 18
  • 62
  • 126
  • 1
    you are pro'ly seeing a different account or session. if the failing method creates a drive map ... that map is for that account. if the drive does not show in your other situation ... then you likely are using a different account. – Lee_Dailey Dec 15 '21 at 14:59
  • That is a good point, @Lee_Dailey. The service executing the user-data script might be using a different account that the one I use to remote connect to the EC2 instance. I will investigate further. – Georgi Koemdzhiev Dec 15 '21 at 15:57
  • good luck! [*grin*] – Lee_Dailey Dec 15 '21 at 17:00

0 Answers0