Skip to content

Commit 850a102

Browse files
authored
Fix parsing of ECS task ID from task ARN (#30)
AWS has undergone a change in the way they format ECS task ARNs. Previously, task IDs looked like: arn:aws:ecs:region:aws_account_id:task/task-id Now, task IDs look like: arn:aws:ecs:region:aws_account_id:task/cluster-name/task-id To account for both versions, always pull the last element of the ARN split by /.
1 parent a75fa2a commit 850a102

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Add ASSIGN_PUBLIC_IP configuration option [#28](https://github.com/azavea/django-ecsmanage/pull/28)
1010

11+
### Fixed
12+
- Fix parsing of ECS task ID from task ARN [#30](https://github.com/azavea/django-ecsmanage/pull/30)
13+
1114
## [2.0.0] - 2020-10-13
1215
### Added
1316
- Add support for Django 3.x and Python 3.8; no actual code changes were required [#14](https://github.com/azavea/django-ecsmanage/pull/14)

ecsmanage/management/commands/ecsmanage.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ def run_task(self, config, task_def_arn, security_group_id, subnet_id, cmd):
200200

201201
task = self.parse_response(self.ecs_client.run_task(**kwargs), "tasks", 0)
202202

203-
# Parse the ask ARN, since ECS doesn't return the task ID.
204-
# Task ARNS look like: arn:aws:ecs:<region>:<aws_account_id>:task/<id>
205-
task_id = task["taskArn"].split("/")[1]
203+
# Task ARNs have at least two formats:
204+
#
205+
# - Old: arn:aws:ecs:region:aws_account_id:task/task-id
206+
# - New: arn:aws:ecs:region:aws_account_id:task/cluster-name/task-id
207+
#
208+
# See: https://docs.aws.amazon.com/AmazonECS/latest/userguide/ecs-account-settings.html#ecs-resource-ids # NOQA
209+
task_id = task["taskArn"].split("/")[-1]
206210
return task_id

0 commit comments

Comments
 (0)