Search code examples
amazon-web-servicescloudaws-cloudformation

Value of property IamInstanceProfile must be of type String


I want to reference my instance profile value from another stack.

If the Instance profile resource would be in the template, I could !Ref Name of the resource

---
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  SSMInstanceProfileStack:
    Description: instance profile stack
    Type: String
    Default: instance-profile

Resources:
  Ec2:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      ImageId: ami-077a5b1762a2dde35
      IamInstanceProfile: 
        - Fn::ImportValue:
            Fn::Sub: "${SSMInstanceProfileStack}-Suffix" 
      Tags:
      - Key: Name
        Value: Ec2SandPit
Outputs:
  Ec2Output:
    Description: A bare bone Ec2 instance 
    Value: !Ref Ec2
    Export:
      Name: !Sub "${AWS::StackName}-Ec2"

I am getting this error, the resource is deployed.

Value of property IamInstanceProfile must be of type String

Is there a fix for this?


Solution

  • IamInstanceProfile should be a string only, not a list of strings. So it should be (remove -):

          IamInstanceProfile: 
            Fn::ImportValue:
              Fn::Sub: "${SSMInstanceProfileStack}-Suffix"