internal static void WriteContainers(DateTime captureTime, string accountId, RegionEndpoint regionEndPoint) { try { var ecsClient = new AmazonECSClient(regionEndPoint); var listClusterResponse = ecsClient.ListClusters(new ListClustersRequest { MaxResults = 100 }); foreach (var cluster in listClusterResponse.ClusterArns) { var ecsResponse = ecsClient.DescribeContainerInstances(new DescribeContainerInstancesRequest { Cluster = cluster }); foreach (var ecs in ecsResponse.ContainerInstances) { string ecsJson = JsonConvert.SerializeObject(ecs); Common.UpdateTopology(captureTime, accountId, regionEndPoint.SystemName, "ecs", ecs.Ec2InstanceId, ecsJson, "UPDATE"); } } } catch (Exception ex) { //Log.Error("Exception occured while reading containers", ex); Log.InfoFormat("Error reading containers: {0}", ex.Message); } }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonECSConfig config = new AmazonECSConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonECSClient client = new AmazonECSClient(creds, config); ListClustersResponse resp = new ListClustersResponse(); do { ListClustersRequest req = new ListClustersRequest { NextToken = resp.NextToken , MaxResults = maxItems }; resp = client.ListClusters(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.ClusterArns) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
public void ECSListClusters() { #region e337d059-134f-4125-ba8e-4f499139facf var client = new AmazonECSClient(); var response = client.ListClusters(new ListClustersRequest { }); List <string> clusterArns = response.ClusterArns; #endregion }
static async Task Main(string[] args) { var basicCredentials = new BasicAWSCredentials("XXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXX"); var client = new AmazonECSClient(basicCredentials, RegionEndpoint.USWest2); // list available clusters in region var regionClusterArn = client.ListClusters(new Amazon.ECS.Model.ListClustersRequest { }).ClusterArns; foreach (var regionClusterName in regionClusterArn) { var clusterServiceArn = (await client.ListServicesAsync(new Amazon.ECS.Model.ListServicesRequest { Cluster = regionClusterName }).ConfigureAwait(false)).ServiceArns; var describeServiceRequest = new Amazon.ECS.Model.DescribeServicesRequest { Cluster = regionClusterName, Services = clusterServiceArn }; // list all available services in cluster var regionClusterService = (await client.DescribeServicesAsync(describeServiceRequest).ConfigureAwait(false)).Services; } }