aws ecs deploy: --cluster "" (empty string) is not treated as unspecified, unlike omitting --cluster
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 13
Description
### Describe the bug
`ECSClient.get_service_details()`, used by `aws ecs deploy`, has a broken conditional for defaulting the `--cluster` value:
```python
def get_service_details(self):
cluster = self._args.cluster
if cluster is None or '':
cluster = 'default'
```
Due to Python operator precedence, this parses as `if (cluster is None) or (''):`. The empty string literal `''` is always falsy, so it contributes nothing to the condition — the `or ''` is dead code. The check is silently equivalent to just `if cluster is None:`.
The command's own help text for `--cluster` says:
> If you do not specify a cluster, the "default" cluster is assumed.
That's true when `--cluster` is omitted entirely (`argparse` leaves it as `None`). But if a caller passes `--cluster ""` — for example a CI/CD pipeline doing `aws ecs deploy --cluster "$CLUSTER_NAME" ...` where `$CLUSTER_NAME` is unset or empty — `cluster` is an empty string, not `None`, so the fallback to `"default"` is skipped and the empty string is sent straight through to `DescribeServices`.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Expected Behavior
`--cluster ""` should be treated the same as omitting `--cluster`, and fall back to the `"default"` cluster, matching the documented behavior.
### Current Behavior
`describe_services` is called with `cluster=''` instead of `cluster='default'`, which does not match the documented "default cluster is assumed" fallback and will fail cluster/service resolution against the ECS API instead of deploying to the default cluster.
Demonstrated directly against `ECSClient.get_service_details()`:
```python
>>> client._args.cluster = ''
>>> client.get_service_details()
# describe_services is invoked with cluster='' instead of cluster='default'
```
### Reproduction Steps
```console
$ CLUSTER_NAME=
$ aws ecs deploy --service my-service --cluster "$CLUSTER_NAME" \
--task-definition file://task-def.json \
--codedeploy-appspec file://appspec.yaml
```
Because `$CLUSTER_NAME` is empty, this passes `--cluster ""`, and the command does not fall back to the `default` cluster the way omitting `--cluster` entirely would.
### Possible Solution
Replace the broken condition with `if not cluster:`, which correctly treats both `None` and `''` as "not specified" and falls back to `'default'` in both cases. I have a PR ready with the fix and regression tests (there was previously no test coverage at all for the cluster-defaulting behavior in `get_service_details`).
### CLI version used
aws-cli/2.36.23 (reproduced on `v2` at 4c331fc)
### Environment details (OS name and version, etc.)
macOS 15 (Darwin 25.2.0), Python 3.12 — not OS-specific, this is a pure logic bug.
Contributor guide
Research direction
Start at ECSClient.get_service_details and trace how the --cluster argument is passed to describe_services. Add regression coverage for omitted and empty --cluster values, then run the relevant AWS CLI tests to verify both cases use the documented default cluster behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100