Amazon.EC2.AmazonEC2Client.DescribeVpcsAsync C# (CSharp) Method

DescribeVpcsAsync() public method

Initiates the asynchronous execution of the DescribeVpcs operation.
public DescribeVpcsAsync ( DescribeVpcsRequest request, System cancellationToken = default(CancellationToken) ) : Task
request DescribeVpcsRequest Container for the necessary parameters to execute the DescribeVpcs operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
return Task
        public Task<DescribeVpcsResponse> DescribeVpcsAsync(DescribeVpcsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DescribeVpcsRequestMarshaller();
            var unmarshaller = DescribeVpcsResponseUnmarshaller.Instance;

            return InvokeAsync<DescribeVpcsRequest,DescribeVpcsResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }

Same methods

AmazonEC2Client::DescribeVpcsAsync ( System cancellationToken = default(CancellationToken) ) : Task

Usage Example

        public async Task<string> GetVpcIdAsync()
        {
            using (var ec2Client = new AmazonEC2Client(credentials, ec2ConfigurationProvider.RegionEndpoint))
            {
                var filters = new List<Filter>
                {
                    new Filter("tag:Product", new List<string> { "Material" }),
                    new Filter("tag:Service", new List<string> { ec2ConfigurationProvider.ServiceName }),
                    new Filter("tag:DeploymentEnvironment", new List<string> { ec2ConfigurationProvider.DeploymentEnvironmentName })

                };
                var response = await ec2Client.DescribeVpcsAsync(new DescribeVpcsRequest { Filters = filters });

                var vpcs = response.Vpcs;

                //get vpc with latest created
                loggerProvider.GetLogger().Debug("Sorting VPCs by Created Tag with most recent time first.");
                vpcs.Sort((p, q) => {
                    var dtP = DateTime.Parse(p.Tags.First(t => t.Key == "Created").Value);
                    var dtQ = DateTime.Parse(q.Tags.First(t => t.Key == "Created").Value);

                    return DateTime.Compare(dtQ, dtP);
                });


                var materialVpc = vpcs.FirstOrDefault();
                if (materialVpc == null)
                {
                    var message = "Could not locate Material API VPC.";
                    loggerProvider.GetLogger().Error(message);
                    throw new Ec2ServiceException(message);
                }

                return materialVpc.VpcId;
            }
        }
AmazonEC2Client