Reputation: 4319
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?
Upvotes: 5
Views: 3826
Reputation: 4319
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.
Upvotes: 10