Add a IAM role that is service linked role

Viewed 779

I'm trying to create a CFN to start up a ECS connected to a ECR an a load balancer on top. But now I get this error:

Resource handler returned message: "Invalid request provided: CreateService error: You cannot specify an IAM role for services that require a service linked role. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: b8a77e87-5715-4d43-b58f-a0843dbee15e; Proxy: null)" (RequestToken: c19a676b-893b-8369-a9b5-75c792c18bd0, HandlerErrorCode: InvalidRequest)

My service block that fails in the events is this.

  service:
    Type: AWS::ECS::Service
    DependsOn: ALBListenerHttps
    Properties:
      Cluster: !Ref 'ECSCluster'
      DesiredCount: '1'
      LaunchType: FARGATE
      LoadBalancers:
      - ContainerName: !Sub ${Environment}-${Name}
        ContainerPort: '3000'
        TargetGroupArn: !Ref 'ECSTG'
      Role: 'arn:aws:iam::{My was id}:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS'
      TaskDefinition: !Ref 'taskdefinition'
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: 'ENABLED'
          Subnets: !Ref 'SubnetId'
1 Answers

You can't use Role if you have NetworkConfiguration. So remove your Role. From docs:

This parameter is only permitted if you are using a load balancer with your service and your task definition does not use the awsvpc network mode.

Related