title: Attach IAM role using cloudformation
body: <p>I am trying to create a webserver (Ec2 instance) with an IAM role of access to S3 bucket using ccloudformation. It creates the role but doesn't attach the role to ec2-instance.</p>
  <pre><code>webserver:
      Type: AWS::EC2::SecurityGroup
      Properties:
        GroupName: sg-webserver
        SecurityGroupIngress:
          - IpProtocol: tcp
            FromPort: 22
            ToPort: 22
            CidrIp: 0.0.0.0/0
            Description: For traffic from Internet
        GroupDescription: Security Group for demo server
        VpcId: !Ref VPC
    EC2Instance:
      Type: AWS::EC2::Instance
      Properties:
        AvailabilityZone: us-east-2a
        BlockDeviceMappings:
          - DeviceName: /dev/xvda
            Ebs:
              DeleteOnTermination: &quot;true&quot;
              VolumeSize: &quot;8&quot;
              VolumeType: gp2
        ImageId: ami-0bdcc6c05dec346bf
        InstanceType: t2.micro
        KeyName: key-webserver
        NetworkInterfaces:
          - Description: Primary network interface
            DeviceIndex: 0
            SubnetId: !Ref SubnetA
            GroupSet:
              - Ref: webserver
    ListS3BucketsInstanceProfile:
      Type: AWS::IAM::InstanceProfile
      Properties:
        Path: &quot;/&quot;
        Roles:
          - Ref: S3FullAccess
    ListS3BucketsPolicy:
      Type: AWS::IAM::Policy
      Properties:
        PolicyName: ListS3BucketsPolicy
        PolicyDocument:
          Statement:
            - Effect: Allow
              Action:
                - s3:List*
              Resource: &quot;*&quot;
        Roles:
          - Ref: S3FullAccess
    S3FullAccess:
      Type: AWS::IAM::Role
      Properties:
        AssumeRolePolicyDocument:
          Version: &quot;2012-10-17&quot;
          Statement:
            - Effect: Allow
              Principal:
                Service:
                  - ec2.amazonaws.com
              Action:
                - sts:AssumeRole
        Path: &quot;/&quot;
  </code></pre>
  <p>The yml file works fine. It creates an ec2-instance and security group but doesnot attach the IAM role to the ec2 Instance</p>