cloudformation, aws, amazon linux 2,

Fix CloudFormation Error: 'The provided target group has target type instance, which is incompatible with the awsvpc network mode specified in the task definition'

Oct 30, 2022 · 1 min read · Post a comment

Recently I needed to create a Network Load Balancer through CF and while creating the target group I stumbled upon this error: The provided target group has target type instance, which is incompatible with the awsvpc network mode specified in the task definition. Let’s see how I resolved the error.

Prerequisites

  • AWS Account
  • CloudFormation Access

Solution

The issue points to you that either in your target group you have set TargetType: instance or you don’t have defined TargetType at all.

  1. If you have set TargetType: instance you need to change it to TargetType: ip.
  2. If you don’t have defined TargetType attribute you need to add TargetType: ip as well.

Here I’m going to paste an example of mine that resolves the issue:

  NlbTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Name: !Sub "${Env}-${Service}-nlb-tg"
      Port: !Ref NLBPort
      Protocol: TCP
      TargetType: ip
      ...

Conclusion

In case you have some other suggestions don’t hesitate to raise them below. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.