aws,

Resolve `Resource handler returned message: Model validation failed (#/ContainerDefinitions/0/Environment: array items are not unique)` error in CloudFormation

May 11, 2022 · 1 min read · Post a comment

While updating some of my CloudFormation templates I stumbled upon the following error:
Resource handler returned message: "Model validation failed (#/ContainerDefinitions/0/Environment: array items are not unique)" .

I quickly realized what might it be and resolved it.

Prerequisites

  • AWS account
  • CloudFormation

Solution

If you closely read the error: Resource handler returned message: "Model validation failed (#/ContainerDefinitions/0/Environment: array items are not unique)" you can spot that some of the resources are not unique. So probably you have duplicate of the same resource with the same value or configuration. I’m my case the error was coming from the EcsTaskDefinition specifically the Environment Variables. I have duplicated the same environment variable by mistake:

EcsTaskDefinition:
    Type: AWS::ECS::TaskDefinition
    DeletionPolicy: Retain
    Properties:
...
       Environment:
         - Name: LICENCE
           Value: "kl5698hy^9"
....
         - Name: LICENCE
           Value: "kl5698hy^9"

The LICENCE variable was duplicated with the same value. So to fix the issue I needed to remove the duplicate and update the CF stack again.

Conclusion

Hope that you will find helpful the advice and solve the issue. Btw, if you have some other suggestions don’t hesitate to share them along and make our lives easier. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.