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.
- If you have set
TargetType: instanceyou need to change it toTargetType: ip. - If you don’t have defined
TargetTypeattribute you need to addTargetType: ipas 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.