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

(aws-ecs): Give Cluster a method that provides task ARNs #26232

Closed
1 of 2 tasks
SamStephens opened this issue Jul 5, 2023 · 2 comments · Fixed by #28381
Closed
1 of 2 tasks

(aws-ecs): Give Cluster a method that provides task ARNs #26232

SamStephens opened this issue Jul 5, 2023 · 2 comments · Fixed by #28381
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@SamStephens
Copy link
Contributor

SamStephens commented Jul 5, 2023

Describe the feature

ARNs for tasks in a Cluster are in the form arn:{partition}:ecs:{region}:{accountId}:task/{clusterName}/{taskId}. It would be useful to have a method that can form these ARNs for you.

The aws-s3 Bucket class provides prior art for this with its arnForObjects method.

I guess this method would be called arnForTasks.

Use Case

In order to grant my task role permissions to the task protection API. My workaround is

        cluster_task_arn = Stack.of(self).format_arn(
            service='ecs',
            resource='task',
            resource_name=f'{fargate_cluster.cluster_name}/*'
        )
        fargate_task_definition.add_to_task_role_policy(
            aws_iam.PolicyStatement(
                actions=["ecs:UpdateTaskProtection"],
                resources=[cluster_task_arn],
            )
        )

With this method, the call would be

        fargate_task_definition.add_to_task_role_policy(
            aws_iam.PolicyStatement(
                actions=["ecs:UpdateTaskProtection"],
                resources=[fargate_cluster.arn_for_tasks('*')],
            )
        )

Proposed Solution

I'm not sure what best practice for forming ARNs within the CDK is, but using formatArn as I do in my example above would work.

Other Information

See also my request for a grantTaskProtection method

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.85.0

Environment details (OS name and version, etc.)

Ubuntu (Windows Subsystem for Linux)

@SamStephens SamStephens added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jul 5, 2023
@khushail
Copy link
Contributor

khushail commented Jul 5, 2023

Thanks for suggesting this feature @SamStephens , it would be a good and useful addition.

@khushail khushail added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2023
@mergify mergify bot closed this as completed in #28381 Dec 22, 2023
mergify bot pushed a commit that referenced this issue Dec 22, 2023
This pull request introduces a new method within the Cluster class, designed to retrieve the Amazon Resource Names (ARNs) of tasks that are part of a given ECS cluster. 


Example of how to get task ARN

```ts
declare cluster: Cluster;
// arn:aws:ecs:{region}:{regionId}:task/{clusterName}/*
const taskArnPattern = cluster.arnForTasks("*");
```


Closes #26232

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

paulhcsun pushed a commit to paulhcsun/aws-cdk that referenced this issue Jan 5, 2024
…28381)

This pull request introduces a new method within the Cluster class, designed to retrieve the Amazon Resource Names (ARNs) of tasks that are part of a given ECS cluster. 


Example of how to get task ARN

```ts
declare cluster: Cluster;
// arn:aws:ecs:{region}:{regionId}:task/{clusterName}/*
const taskArnPattern = cluster.arnForTasks("*");
```


Closes aws#26232

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
2 participants