https://pulumi.com logo
#python
Title
# python
t

thankful-stone-34269

11/10/2022, 12:11 AM
I'm confused how to create an IAM role for an ec2 machine and then use it. The error message is super confusing. First I create an IAM role:
Copy code
machine_role = aws.iam.Role("dockerbuilder-role", ...)
and then I try to create an EC2 instance that uses this role:
Copy code
server = aws.ec2.Instance('dockerbuilder-pulumi',
    iam_instance_profile=machine_role,
...)
The error message (which annoyingly takes 2 minutes to resolve annoyingly) is
InvalidParameterValue: Value (dockerbuilder-role-908245c) for parameter iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name
. Now if I instantiate the Instance with `
Copy code
iam_instance_profile="dockerbuilder-role-908245c",
it works. How do I get the name out of the role object to pass into the instance?
Same problem if I try
Copy code
iam_instance_profile=machine_role.name,
Figured it out. Not sure why I thought it was working before - I think I was confused. But I needed.
Copy code
machine_profile = aws.iam.InstanceProfile("dockerbuilder-profile", role=machine_role.name)

...

    iam_instance_profile=machine_profile,
194 Views