EC2 Screen with DescribeInstanceStatus Procedure - AWS SDK

I am trying to filter out EC2 instances using the AWS SDK in .NET, and although I have seen a lot of threads on SO and on other sites of people solving this problem, I have not tried anything at my end.

So, as a last resource, I come to you guys for help. Can anyone shed some light on what I am missing? I know that it is very likely that I am doing something stupid, but I can not afford to spend too much time solving this problem.

This is a piece of code that I use to filter out an EC2 instance (get its metadata) using this tag name:

DescribeInstanceStatusRequest req = new DescribeInstanceStatusRequest (); req.Filters.Add (new Filter() { Name = "tag:Name", Values = new List <string> () { "some_random_name" } }); // Executing request & fetching response DescribeInstanceStatusResponse resp = m_ec2Client.DescribeInstanceStatus (req); 

But I continue to work on this exception:

Invalid filter tag: name '

I replaced the filter name ("tag: Name" in the example) with several filters listed in the documentation (for example, "tag-key", "tag-value", "tag: key = value"), but nothing works.

Thanks to everyone in advance :)

+5
source share
2 answers

After more thorough research, I found out that the "DescribeInstanceStatus" procedure does not support tag search, but I found a somewhat "simple" way to do this. I will post it here if someone goes into the same situation.

Here's how:

 DescribeInstancesRequest req = new DescribeInstancesRequest (); req.Filters.Add (new Filter () { Name = "tag-value", Values = new List <string> () { "something" }}); // Executing request & fetching response DescribeInstancesResponse resp = m_ec2Client.DescribeInstances (req); return resp.Reservations.SelectMany (x => x.Instances).Where (y => y.State.Name == InstanceStateName.Pending || y.State.Name == InstanceStateName.Running).ToList (); {code} 

In theory, using this procedure, you can use any of the filters listed in the "Supported Filters" table in the documentation .

+4
source

It could be ...

 // Executing request & fetching response DescribeInstancesResponse resp = m_ec2Client.DescribeInstances ( new DescribeInstancesRequest() { Filters = new List<Filter>() { new Filter("tag:Name", new List<string>(){"some_random_name"}) } }); 
0
source

Source: https://habr.com/ru/post/1246195/


All Articles