HOWTO: Create AWS EC2 spot instance with the specific IAM Role

Get IAMInstanceProfile

$iam=[Amazon.AWSClientFactory]::CreateAmazonIdentityManagementClient($awsKeyId, $awsKey)
$req = (new-object Amazon.IdentityManagement.Model.GetInstanceProfileRequest).WithInstanceProfileName('S3Reader')
$res = $iam.GetInstanceProfile($req1).GetInstanceProfileResult
$iamprofile = (new-object Amazon.EC2.Model.IAMInstanceProfile).WithArn($res.InstanceProfile.Arn).WithId($res.InstanceProfile.InstanceProfileId)

Create LaunchSpecification

$spec = (new-object Amazon.EC2.Model.LaunchSpecification).WithInstanceProfile($iamprofile).WithSecurityGroup('your security group')
$spec.ImageId = 'ami0000000'
$spec.InstanceType = 'm1.small'

Create spot request

$ec2=[Amazon.AWSClientFactory]::CreateAmazonEC2Client($awsKeyId, $awsKey)
$req = new-object Amazon.EC2.Model.RequestSpotInstancesRequest
$req.InstanceCount = 1
$req.SpotPrice = '0.02'
$req.LaunchSpecification = $spec
$ec2.RequestSpotInstances($req).RequestSpotInstancesResult.SpotInstanceRequest[0].SpotInstanceRequestId

Windows Core: Install PowerShell 3.0 by using PowerShell 2.0

Run the script below in the PowerShell 2.0 on your Windows Core

(new-object System.Net.WebClient).DownloadFile('http://download.microsoft.com/download/3/6/1/361DAE4E-E5B9-4824-B47F-6421A6C59227/dotNetFx40_Full_x86_x64_SC.exe', 'c:\dotNetFx40_Full_x86_x64_SC.exe')
.\dotNetFx40_Full_x86_x64_SC.exe
(new-object System.Net.WebClient).DownloadFile('http://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.1-KB2506143-x64.msu', 'c:\Windows6.1-KB2506143-x64.msu')
.\Windows6.1-KB2506143-x64.msu

It is not unattended installation. You will be prompted several times to click Next.
net45
net45

AWS PowerShell store credentials

The AWS Tools for Windows PowerShell enable you to set up default credentials and a default region which can be used in every PowerShell session you run. This approach avoids having to specify these every time you run a cmdlet. The default credentials are placed in the credentials store under the profile name, AWS PS Default.

Initialize-AWSDefaults -AccessKey AKIAIOSFODNN7EXAMPLE -SecretKey wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY -Region us-east-1