0

I am trying to create a stack for ECS service with conditional statement for logging on ECS TaskDefination. I am trying to send the logs to different sources based on Environment but it is failing with below during stack update.

Error Resource handler returned message: "Model validation failed (#/ContainerDefinitions/0/Memory: expected type: Number, found: String #/ContainerDefinitions/0/Cpu: expected type: Number, found: String #/ContainerDefinitions/0/LogConfiguration: expected type: JSONObject, found: JSONArray #/ContainerDefinitions/0/PortMappings/0/ContainerPort: expected type: Number, found: String)"

Conditions:
  HasDefaultLog:
    !Or [ !Equals [ !Ref EnvType, 'Prod' ], !Equals [ !Ref EnvType, 'Dev' ], !Equals [ !Ref EnvType, 'Sit' ] ]

ContainerDefinitions:
        - Name: !Ref 'ServiceName'
          Cpu: !Ref 'ContainerCpu'
          Memory: !Ref 'ContainerMemory'
          Image: !Ref 'ImageUrl'
          PortMappings:
            - ContainerPort: !Ref 'ContainerPort'
          LogConfiguration:
            -
              Fn::If:
                - HasDefaultLog
                -
                  LogDriver: !Ref LogDriver
                  Options:
                    syslog-address: !Ref LogDestination
                    tag:  !Ref ServiceName
                -
                  LogDriver: awsfirelens
                  Options:
                    Name: newlogdriver

The same works with below and able to see the logs in destination

LogConfiguration:
  LogDriver: !Ref LogDriver
  Options:
    syslog-address: !Ref LogDestination
    tag:  !Ref ServiceName

1 Answer 1

0

LogConfiguration is object, not a list of objects. Sp you don't need - at the beginning:

          LogConfiguration:
              Fn::If:
                - HasDefaultLog
                -
                  LogDriver: !Ref LogDriver
                  Options:
                    syslog-address: !Ref LogDestination
                    tag:  !Ref ServiceName
                -
                  LogDriver: awsfirelens
                  Options:
                    Name: newlogdriver
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.