Search code examples
amazon-web-servicesaws-cloudformation

How can I create IAM Role Dropdown in Cloudformation Template Parameters


I'm looking for a way to list out existing IAM roles in a Cloudformation Template in a similar way to listing say EC2 Key Pairs. Below is an example of what I'm trying with both EC2 Key Pairs and IAM Roles however Cloudformation throws an error saying that "RoleName" does not exist.

"KeyName": {
  "Description" : "Choose a Key Pair that is available in this region",
  "Type": "AWS::EC2::KeyPair::KeyName",
  "ConstraintDescription": "Must be the name of an existing EC2 Key Pair"
},
"ServiceRole": {
  "Description" : "Choose an IAM Role that is available in this region",
  "Type": "AWS::IAM::Role::RoleName",
  "ConstraintDescription": "Must be the name of an existing IAM Role"
},

Screenshot of Cloudformation Interface Any ideas if this is possible to achieve?


Solution

  • Not all types are supported in dropdown lists, and IAM Roles are not a supported type. So you cannot get a dropdown for IAM roles. Instead, you will have to use a simple text box.

    Here is the current list of supported parameter types:

    • String
    • Number
    • List<Number>
    • CommaDelimitedList
    • AWS::EC2::AvailabilityZone::Name
    • AWS::EC2::Image::Id
    • AWS::EC2::Instance::Id
    • AWS::EC2::KeyPair::KeyName
    • AWS::EC2::SecurityGroup::GroupName
    • AWS::EC2::SecurityGroup::Id
    • AWS::EC2::Subnet::Id
    • AWS::EC2::Volume::Id
    • AWS::EC2::VPC::Id
    • AWS::Route53::HostedZone::Id
    • List<AWS::EC2::AvailabilityZone::Name>
    • List<AWS::EC2::Image::Id>
    • List<AWS::EC2::Instance::Id>
    • List<AWS::EC2::SecurityGroup::GroupName>
    • List<AWS::EC2::SecurityGroup::Id>
    • List<AWS::EC2::Subnet::Id>
    • List<AWS::EC2::Volume::Id>
    • List<AWS::EC2::VPC::Id>
    • List<AWS::Route53::HostedZone::Id>

    Source: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-specific-parameter-types