title: Invalid IAM Instance Profile name
body: <p>I am creating a Terraform script which creates a IAM role to be assumbed by EC2 instance via Launch Template. I have a simple lambda function (boto3/python) that creates/launches the EC2 instance using the Launch Template. However, I am getting this error when I run the lambda function:</p>
  <pre><code>&quot;errorMessage&quot;: &quot;An error occurred (InvalidParameterValue) when calling the RunInstances operation:
  Value (arn:aws:iam::xxx:instance-profile/RigstopgapInstanceProfile) for parameter iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name&quot;,
    &quot;errorType&quot;: &quot;ClientError&quot;,
  </code></pre>
  <p>My terraform code is this one:</p>
  <pre><code>resource &quot;aws_launch_template&quot; &quot;rig_stopgap&quot; {
    name          = &quot;rig_stopgap&quot;
    image_id      = var.ami_image
    instance_type = var.instance_type
  
    iam_instance_profile {
      name = aws_iam_instance_profile.rig_stopgap.arn
    }
    ...
  }
  
  resource &quot;aws_iam_instance_profile&quot; &quot;rig_stopgap&quot; {
    name = &quot;RigstopgapInstanceProfile&quot;
    role = aws_iam_role.rigs_stopgap_ec2.name
  }
  
  # EC2 &quot;Trust relationships&quot; policy (necessary to allow the instance to assume a role)
  data &quot;aws_iam_policy_document&quot; &quot;trust_relationships_ec2_policy&quot; {
    statement {
      actions = [&quot;sts:AssumeRole&quot;]
      principals {
        type        = &quot;Service&quot;
        identifiers = [&quot;ec2.amazonaws.com&quot;]
      }
    }
  }
  
  # EC2 main policy
  resource &quot;aws_iam_policy&quot; &quot;rigs_stopgap_ec2_policy&quot; {
    name        = &quot;RigsStopgapPolicy&quot;
    description = &quot;Rigs Stopgap Policy allowing access to all of the necessary resources&quot;
  
    policy = &lt;&lt;EOF
  {
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
      {
        &quot;Action&quot;: [
          &quot;dynamodb:UpdateItem&quot;
        ],
        &quot;Effect&quot;: &quot;Allow&quot;,
        &quot;Resource&quot;: &quot;${aws_dynamodb_table.rigs_stopgap.arn}&quot;
      }
    ]
  }
  EOF
  }
  
  # Attach the ec2 policy 
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;attach_ec2_instance_policy&quot; {
    role       = aws_iam_role.rigs_stopgap_ec2.name
    policy_arn = aws_iam_policy.rigs_stopgap_ec2_policy.arn
  }
  
  resource &quot;aws_iam_role&quot; &quot;rigs_stopgap_ec2&quot; {
    name               = &quot;RigsStopgapRole&quot;
    assume_role_policy = data.aws_iam_policy_document.trust_relationships_ec2_policy.json
    tags               = var.common_tags
  }
  </code></pre>
  <p>My Lambda code:</p>
  <pre><code>import boto3
  
  ec2 = boto3.resource('ec2')
  lt = {
      'LaunchTemplateName': 'rig_stopgap',
      'Version': '$Latest'
  }
  
  
  def handler(event, context):
  
      instances = ec2.create_instances(
          LaunchTemplate=lt,
          MinCount=1,
          MaxCount=1
      )
  </code></pre>
  <p>What am I missing?</p>
  <p>Update:
  When I open the Launch Template in the AWS Console and navigate to the Instance Profile section it apparantly cannot find it:
  <a href="https://i.stack.imgur.com/R1qFt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R1qFt.png" alt="enter image description here" /></a></p>