From 70b6354aa07d17a5ecde2274f2c266371c868390 Mon Sep 17 00:00:00 2001 From: Oleksandr Novak Date: Mon, 30 May 2022 11:51:33 +0200 Subject: [PATCH] ecs_service - fix validation for `placementConstraints` (#1170) ecs_service - fix validation for `placementConstraints` SUMMARY Fixes #1058 ISSUE TYPE Bugfix Pull Request COMPONENT NAME ecs_service Reviewed-by: Markus Bergholz Reviewed-by: Oleksandr Novak Reviewed-by: Alina Buzachis --- ecs_service.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ecs_service.py b/ecs_service.py index 66f20b63d81..4f94a452ce9 100644 --- a/ecs_service.py +++ b/ecs_service.py @@ -113,6 +113,7 @@ type: str expression: description: A cluster query language expression to apply to the constraint. + required: false type: str placement_strategy: description: @@ -584,7 +585,6 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan clientToken=client_token, role=role, deploymentConfiguration=deployment_configuration, - placementConstraints=placement_constraints, placementStrategy=placement_strategy ) if network_configuration: @@ -597,6 +597,13 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan params['healthCheckGracePeriodSeconds'] = health_check_grace_period_seconds if service_registries: params['serviceRegistries'] = service_registries + + # filter placement_constraint and left only those where value is not None + # use-case: `distinctInstance` type should never contain `expression`, but None will fail `str` type validation + if placement_constraints: + params['placementConstraints'] = [{key: value for key, value in constraint.items() if value is not None} + for constraint in placement_constraints] + # desired count is not required if scheduling strategy is daemon if desired_count is not None: params['desiredCount'] = desired_count @@ -674,7 +681,7 @@ def main(): elements='dict', options=dict( type=dict(type='str'), - expression=dict(type='str') + expression=dict(required=False, type='str') ) ), placement_strategy=dict(