Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-ecs-72910.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "ecs",
"description": "Fix `aws ecs deploy` falling back to the correct behavior for `--cluster \"\"` (an empty string, e.g. from an unset shell variable) the same way it already does when `--cluster` is omitted, instead of passing the empty string through to the ECS API"
}
2 changes: 1 addition & 1 deletion awscli/customizations/ecs/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def __init__(self, session, parsed_args, parsed_globals, user_agent_extra):
def get_service_details(self):
cluster = self._args.cluster

if cluster is None or '':
if not cluster:
cluster = 'default'

try:
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/customizations/ecs/test_ecsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,40 @@ def test_client_config(self):
create_args[1]['config'].user_agent_extra,
expected_user_agent_extra,
)

def _get_service_details_with_cluster(self, cluster):
args = Namespace(cluster=cluster, service='my-service')
test_client = ECSClient(
self.session, args, self.global_args, ECSDeploy.USER_AGENT_EXTRA
)
test_client._client = mock.Mock()
test_client._client.describe_services.return_value = {
'services': [
{
'serviceArn': (
'arn:aws:ecs:us-east-1:123456789012:service/my-service'
),
'serviceName': 'my-service',
'clusterArn': (
'arn:aws:ecs:us-east-1:123456789012:cluster/default'
),
}
]
}
test_client.get_service_details()
return test_client._client.describe_services.call_args[1]['cluster']

def test_get_service_details_defaults_cluster_when_not_specified(self):
used_cluster = self._get_service_details_with_cluster(None)
self.assertEqual(used_cluster, 'default')

def test_get_service_details_defaults_cluster_when_empty_string(self):
# A caller may pass an empty string for --cluster (e.g. by
# interpolating an unset shell variable), which should be treated
# the same as not specifying a cluster at all.
used_cluster = self._get_service_details_with_cluster('')
self.assertEqual(used_cluster, 'default')

def test_get_service_details_uses_specified_cluster(self):
used_cluster = self._get_service_details_with_cluster('my-cluster')
self.assertEqual(used_cluster, 'my-cluster')