Discovering a method to achieve this task is possible when equipped with the Service name as well.
import { Cluster, FargateService } from '@aws-cdk/aws-ecs';
private updateClusterServices(scope: Construct, cluster: Cluster, serviceName: string): void {
const service = FargateService.fromFargateServiceAttributes(scope, 'FindFargateServices', {
cluster: cluster,
serviceName: serviceName,
});
console.log(service.serviceArn);
// process service accordingly
}
The output seems to be the TaskSet serviceArn.
arn:aws:ecs:ap-southeast-2:1234567890:service/backend
This was the outcome upon comparison with the CLI output.
$ aws ecs describe-services --cluster blue-green-cluster --services backend
{
"services": [
{
"serviceArn": "arn:aws:ecs:ap-southeast-2:1234567890:service/blue-green-cluster/backend",
"serviceName": "backend",
"clusterArn": "arn:aws:ecs:ap-southeast-2:1234567890:cluster/blue-green-cluster",
...
"taskSets": [
{
"taskSetArn": "arn:aws:ecs:ap-southeast-2:1234567890:task-set/blue-green-cluster/backend/ecs-svc/2091139980078414071",
"serviceArn": "arn:aws:ecs:ap-southeast-2:1234567890:service/backend",
"clusterArn": "arn:aws:ecs:ap-southeast-2:1234567890:cluster/blue-green-cluster",
...
}