SI2
SI2

Reputation: 53

Can't run Powershell user data scripts on Windows EC2

I am using the Javascript SDK to run Windows Server2019 EC2 instances - the AMI I'm using is a custom AMI. Through the SDK, I'm inputting this user data:

<powershell>
    Copy-S3Object -BucketName mybucket -KeyPrefix myprefix -LocalFolder C:\Users\myuser\Desktop -Region ap-southeast-2
</powershell>
<persist>true</persist>

When I select the running instance and view user data, the above user data correctly shows.

I have added the appropriate IAM role to the instance as it works when I manually run the base Windows Server2019 instance from the console with the same user data and IAM role.

But when running it from the SDK, the EC2 logs show that:

<powershell> tag was provided.. running powershell content
Failed to get metadata: The result from http://169.254.169.254/latest/user-data was empty
Unable to execute userdata: Userdata was not provided

Upvotes: 0

Views: 2075

Answers (1)

SI2
SI2

Reputation: 53

The trick was to create the AMI using sysprep as shown here.

Upvotes: 1

Related Questions