The credentials that you use with your Ruby script do not have permission to run the instance using the "IAM" test role. You need to change the policy for this user and grant him IAM: PassRole permission, for example:
{ "Statement": [{ "Effect":"Allow", "Action":"ec2:RunInstances", "Resource":"*" }, { "Effect":"Allow", "Action":"iam:PassRole", "Resource":"arn:aws:iam::xxxxxxxxxxx:role/test" }] }
This is a security feature — it is possible that IAM is not configured correctly to allow privilege escalation, which is why AWS uses the "secure by default" policy.
You can also use this policy to allow your users to run instances using any IAM role, but before that you must consider the security implications:
{ "Effect":"Allow", "Action":"iam:PassRole", "Resource":"*" }]
Link: http://docs.amazonwebservices.com/IAM/latest/UserGuide/role-usecase-ec2app.html
source share