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 =

1 2 3 5