# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # ecs_task_definition_memory_hard_limit_check # # Description: # This control checks whether Amazon Elastic Container Service (ECS) task definitions have specified a memory limit for container definitions. # # Reports on: # AWS::ECS::TaskDefinition # # Evaluates: # AWS CloudFormation, AWS CloudFormation hook # # Rule Parameters: # None # # Scenarios: # Scenario: 1 # Given: The input document is an AWS CloudFormation document or CloudFormation hook document # And: The input document does not contain an ECS task definition resource # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation document or CloudFormation hook document # And: The input document contains an ECS task definition resource # And: 'ContainerDefinitions' property is not present or is an empty list # Then: SKIP # Scenario: 3 # Given: The input document is an AWS CloudFormation document or CloudFormation hook document # And: The input document contains an ECS task definition resource # And: 'ContainerDefinitions' property is present and is not an empty list # And: One or more containers defined in 'ContainerDefinitions' do not have 'Memory' property set # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation document or CloudFormation hook document # And: The input document contains an ECS task definition resource # And: 'ContainerDefinitions' property is present and is not an empty list # And: One or more containers defined in 'ContainerDefinitions' have 'Memory' property set to an integer # value less than four (< 4) # Then: FAIL # Scenario: 5 # Given: The input document is an AWS CloudFormation document or CloudFormation hook document # And: The input document contains an ECS task definition resource # And: 'ContainerDefinitions' property is present # And: All containers defined in 'ContainerDefinitions' have 'Memory' property set to an integer value # greater than or equal to four (>= 4) # Then: PASS # # Constants # let ECS_TASK_DEFINITION_TYPE = "AWS::ECS::TaskDefinition" let INPUT_DOCUMENT = this # # Assignments # let ecs_task_definitions = Resources.*[ Type == %ECS_TASK_DEFINITION_TYPE ] # # Primary Rules # rule ecs_task_definition_memory_hard_limit_check when is_cfn_template(%INPUT_DOCUMENT) %ecs_task_definitions not empty { check(%ecs_task_definitions.Properties) << [CT.ECS.PR.7]: Require an Amazon ECS task definition to have a specific memory usage limit [FIX]: Set the 'Memory' property in 'ContainerDefinitions' for Amazon ECS task definitions. >> } rule ecs_task_definition_memory_hard_limit_check when is_cfn_hook(%INPUT_DOCUMENT, %ECS_TASK_DEFINITION_TYPE) { check(%INPUT_DOCUMENT.%ECS_TASK_DEFINITION_TYPE.resourceProperties) << [CT.ECS.PR.7]: Require an Amazon ECS task definition to have a specific memory usage limit [FIX]: Set the 'Memory' property in 'ContainerDefinitions' for Amazon ECS task definitions. >> } # # Parameterized Rules # rule check(ecs_task_definition) { %ecs_task_definition [filter_container_definitions_is_present(this)]{ ContainerDefinitions[*] { # Scenario 3 Memory exists # Scenario 4 and 5 Memory >= 4 } } } rule filter_container_definitions_is_present(ecs_task_definition) { %ecs_task_definition { # Scenario 2 ContainerDefinitions exists ContainerDefinitions is_list ContainerDefinitions not empty } } # # Utility Rules # rule is_cfn_template(doc) { %doc { AWSTemplateFormatVersion exists or Resources exists } } rule is_cfn_hook(doc, RESOURCE_TYPE) { %doc.%RESOURCE_TYPE.resourceProperties exists }