There are more AWS SDK examples available in the AWS Doc SDK Examples
Use ListServices with an AWS SDK or CLI
The following code examples show how to use ListServices.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- .NET
-
- SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. /// <summary> /// List service ARNs available. /// </summary> /// <param name="clusterARN">The arn of the ECS cluster.</param> /// <returns>The ARN list of services in given cluster.</returns> public async Task<List<string>> GetServiceARNSAsync(string clusterARN) { List<string> serviceArns = new List<string>(); var request = new ListServicesRequest { Cluster = clusterARN }; // Call the ListServices API operation and get the list of service ARNs var serviceList = _ecsClient.Paginators.ListServices(request); await foreach (var serviceARN in serviceList.ServiceArns) { if (serviceARN is null) continue; serviceArns.Add(serviceARN); } if (serviceArns.Count == 0) { _logger.LogWarning($"No services found in cluster {clusterARN} ."); } return serviceArns; }-
For API details, see ListServices in AWS SDK for .NET API Reference.
-
- CLI
-
- AWS CLI
-
To list the services in a cluster
The following
list-servicesexample shows how to list the services running in a cluster.aws ecs list-services --clusterMyClusterOutput:
{ "serviceArns": [ "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService" ] }For more information, see Services in the Amazon ECS Developer Guide.
-
For API details, see ListServices
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example lists all services running in your default cluster.
Get-ECSClusterServiceExample 2: This example lists all services running in the specified cluster.
Get-ECSClusterService -Cluster myCluster-
For API details, see ListServices in AWS Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: This example lists all services running in your default cluster.
Get-ECSClusterServiceExample 2: This example lists all services running in the specified cluster.
Get-ECSClusterService -Cluster myCluster-
For API details, see ListServices in AWS Tools for PowerShell Cmdlet Reference (V5).
-