CloudFormation yaml - How to force number type?

こ雲淡風輕ζ 提交于 2021-01-27 21:14:39

问题


I'm trying to create an ECS task definition as part of a CloudFormation stack.

My task definition so far looks like this...

  TaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      RequiresCompatibilities:
        - EC2
      ExecutionRoleArn: !Ref MyTaskRole
      ContainerDefinitions:
        - Name: !Ref ServiceName
          Image: amazon/amazon-ecs-sample
          PortMappings:
            - ContainerPort: 3000
              HostPort: 0
              Protocol: tcp
          MemoryReservation: 128

When I try to run this, I get the following error...

#/ContainerDefinitions/0/MemoryReservation: expected type: Number, found: String

So it seems that CloudFormation is converting 128 to a string, and then the stack fails.

What is the correct way to define this value so that it remains a number?


回答1:


It turned out that the error that was being reported by CloudFormation actually wasn't anything to do with the failure. The code above was perfectly fine.

In my case the problem was with the way I'd defined the logging section which appeared later in the template.

The takeaway from this, is that CloudFormation is very confusing to debug, and if you receive an error like this, don't assume it is what's actually causing the stack to fail.

To find the actual problem, I had to first remove the properties which were causing the type conversion error, MemoryReservation and PortMappings, and then it showed an error about the way I'd defined my logging section. After fixing that fault, I was able to re-add the other properties, and it worked fine.

I suspect now that because my logging section was incorrect, the whole ContainerDefinitions perhaps wasn't being parsed correctly, potentially causing the misleading type mismatch error.



来源:https://stackoverflow.com/questions/64327964/cloudformation-yaml-how-to-force-number-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!