Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved InvalidParameterException in aws_ecs_service table when listing tags for older services. Closes #2388 #2410

Merged
merged 6 commits into from
Feb 21, 2025

Conversation

ParthaI
Copy link
Contributor

@ParthaI ParthaI commented Feb 11, 2025

Integration test logs

Logs
Add passing integration test logs here

Example query results

Results
> select service_name, tags_src, tags from aws_ecs_service;
+-----------------+-------------------------------------------------------------+-----------------------------+
| service_name    | tags_src                                                    | tags                        |
+-----------------+-------------------------------------------------------------+-----------------------------+
| test-53-service | [{"Key":"help","Value":"me"},{"Key":"foo1","Value":"bar1"}] | {"foo1":"bar1","help":"me"} |
+-----------------+-------------------------------------------------------------+-----------------------------+

@ParthaI ParthaI requested a review from misraved February 11, 2025 10:06
@ParthaI ParthaI self-assigned this Feb 11, 2025
@ParthaI ParthaI linked an issue Feb 11, 2025 that may be closed by this pull request
@misraved
Copy link
Contributor

misraved commented Feb 13, 2025

@ParthaI has the arn format changed completely? What happens to the resources that still use the old format?

@ParthaI
Copy link
Contributor Author

ParthaI commented Feb 13, 2025

@misraved,

Yes, the ARN format has changed, and currently, AWS supports both formats, as mentioned in this documentation.

We might need to upgrade the resource, but it's unclear how long AWS will continue supporting the old format.

Tasks launched by an Amazon ECS service can only receive the new ARN and resource ID format if the service was created on or after November 16, 2018, and the user who created the service has opted in to the new format for tasks.

The timeline for the opt-in and opt-out periods for the new Amazon Resource Name (ARN) and resource ID format for Amazon ECS resources ended on April 1, 2021. By default, all accounts are opted in to the new format. All new resources created receive the new format, and you can no longer opt out.

@misraved
Copy link
Contributor

@ParthaI can we update the plugin code to use the new ARN format to make the ListTagsForResource API call?

@thomasklemm
Copy link
Contributor

@ParthaI Managed to install it and run the plugin from this branch. Now I'm getting the following error.

ERROR:  rpc error: code = Internal desc = aws_production: rpc error: code = Internal desc = hydrate function getEcsServiceTags failed with panic runtime error: invalid memory address or nil pointer dereference

Query:

select 
  account_id,
  region,
  arn,
  tags -- Fetching tags causes the issue
from
  aws_ecs_service;

It's again pretty hard to pinpoint it to the specific record causing it. Does the error message already help you?

@ParthaI
Copy link
Contributor Author

ParthaI commented Feb 19, 2025

Ah, my apologies for the oversight. I have now pushed a fix, and it should work as expected.

The root cause of the issue was that the list API call for the cluster did not return the ClusterName. To retrieve the cluster name, we need to make a Get API call instead.

Could you please try again after pulling the latest changes from the branch?

Note: It would be helpful to verify whether the cluster name is being returned for older clusters before running the query to fetch the tags for the services.

Thank you!

@thomasklemm
Copy link
Contributor

thomasklemm commented Feb 19, 2025

@ParthaI Thank you very much for addressing this so quickly!

I think it's a good step further, but I get another error:

ERROR: rpc error: code = Unknown desc = aws_1234567890: operation error ECS: ListTagsForResource, https response error StatusCode: 400, RequestID: 84644e43-0be9-4075-8aa1-c4c1ecc70bf0, InvalidParameterException: The specified service does not have the longArn format. Only services created after opting in will have the new format.

In terms of cluster names, select * from aws_ecs_cluster (not _service) is able to return all the cluster names for clusters of any age with this PR (I can't say right now how it behaved before but can roll it back and and check). The aws_ecs_service table doesn't have a cluster name column as far as I see, only the cluster_arn, that one seems to get returned properly.

Query:

select 
  service.account_id,
  service.region,
  service.arn,
  service.cluster_arn,
  cluster.cluster_name as cluster_name, -- All cluster names look fine here
  cluster.tags as cluster_tags
  -- service.tags as service_tags -- This causes the error
from
  aws_ecs_service service
left join aws_ecs_cluster cluster
  on cluster.cluster_arn = service.cluster_arn;

@ParthaI
Copy link
Contributor Author

ParthaI commented Feb 19, 2025

Hmm, the error indicates that we cannot make the API call by updating the ARN format for the older service.

Could you please confirm whether the AWS CLI command successfully retrieves the tag details for the older service? If so, could you kindly share the CLI command along with the specific ARN format used for the older service? This would help us update the table code accordingly to match the correct format.

@ParthaI
Copy link
Contributor Author

ParthaI commented Feb 19, 2025

Furthermore, according to the AWS documentation, to tag a service that follows the older ARN format, you must migrate it to the long ARN format.

Documentation Reference: AWS ECS API - TagResource

However, I couldn't find any documentation stating that the ListTagsForResource API cannot be used to retrieve tags for older services.

@misraved misraved merged commit edba705 into main Feb 21, 2025
1 check passed
@misraved misraved deleted the issue-2388 branch February 21, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tags cannot be fetched for aws_ecs_service table
3 participants