Skip to content

Commit

Permalink
fix: parse ECS Task State Change events correctly (#196)
Browse files Browse the repository at this point in the history
According to the [ECS Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html#ecs_task_events), the field of a ECS Task State Change event that has the task's description is called `detail`.

There is a `details` field as well, but that's nested within the elements of the `detail.attachments` array.

Fixes #168
  • Loading branch information
pygaissert authored Jan 31, 2023
1 parent b86126e commit 5d857d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lambda/assign-public-ip/lib/queue_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def collect_event_task_info(self, event, reference_record: DdbRecord):
running_task_collector = RunningTaskCollector(ec2_client=self.ec2_client, reference_record=reference_record)
stopped_tasks = []
for message in decode_records(event):
if 'details' not in message:
if 'detail' not in message:
logging.info(f'Received a non-task state message {message}')
continue

task_description = message['details']
task_description = message['detail']

group = task_description['group']
if group != f'service:{self.service_name}':
Expand Down
10 changes: 5 additions & 5 deletions test/assign-public-ip.integ.snapshot/aws-ecs-integ.assets.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"files": {
"c5f118435f964bda4ff99dcb8b7e6a132f386d0e06601c019a5d0050a60b7a02": {
"63997c98a36563198603dd944433ccada81fcdb39b2d5456dfc0eafd27880258": {
"source": {
"path": "asset.c5f118435f964bda4ff99dcb8b7e6a132f386d0e06601c019a5d0050a60b7a02",
"path": "asset.63997c98a36563198603dd944433ccada81fcdb39b2d5456dfc0eafd27880258",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c5f118435f964bda4ff99dcb8b7e6a132f386d0e06601c019a5d0050a60b7a02.zip",
"objectKey": "63997c98a36563198603dd944433ccada81fcdb39b2d5456dfc0eafd27880258.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down Expand Up @@ -40,15 +40,15 @@
}
}
},
"d8a9204d503c4b76990c77382242824cefbffb786db6b6b8a9ced3ab35b8d444": {
"06af30c77f9df1b1314c7e42e674b5b75cbe2841251ba21438e7eb6f0e18abf3": {
"source": {
"path": "aws-ecs-integ.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "d8a9204d503c4b76990c77382242824cefbffb786db6b6b8a9ced3ab35b8d444.json",
"objectKey": "06af30c77f9df1b1314c7e42e674b5b75cbe2841251ba21438e7eb6f0e18abf3.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "c5f118435f964bda4ff99dcb8b7e6a132f386d0e06601c019a5d0050a60b7a02.zip"
"S3Key": "63997c98a36563198603dd944433ccada81fcdb39b2d5456dfc0eafd27880258.zip"
},
"Role": {
"Fn::GetAtt": [
Expand Down Expand Up @@ -794,7 +794,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "c5f118435f964bda4ff99dcb8b7e6a132f386d0e06601c019a5d0050a60b7a02.zip"
"S3Key": "63997c98a36563198603dd944433ccada81fcdb39b2d5456dfc0eafd27880258.zip"
},
"Role": {
"Fn::GetAtt": [
Expand Down

0 comments on commit 5d857d8

Please sign in to comment.