public DescribeSubnetsAsync ( DescribeSubnetsRequest request, System cancellationToken = default(CancellationToken) ) : Task |
||
request | DescribeSubnetsRequest | Container for the necessary parameters to execute the DescribeSubnets operation. |
cancellationToken | System | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// |
Результат | Task |
public async Task<string> GetPrivateSubnetIdAsync(string vpcId, string availabilityZone) { using (var ec2Client = new AmazonEC2Client(credentials, ec2ConfigurationProvider.RegionEndpoint)) { var allSubnetsInMyVpcAndAz = await ec2Client.DescribeSubnetsAsync(new DescribeSubnetsRequest { Filters = new List<Filter> { new Filter {Name = "vpc-id", Values = new List<string> {vpcId}}, new Filter {Name = "availabilityZone", Values = new List<string> {availabilityZone}} } }); var privateSubnet = allSubnetsInMyVpcAndAz.Subnets.SingleOrDefault(s => s.Tags.Any(t => string.Equals(t.Key, "AccessLevel", StringComparison.CurrentCultureIgnoreCase) && string.Equals(t.Value, "private", StringComparison.CurrentCultureIgnoreCase))); if (privateSubnet == null) { var message = $"Could not locate private subnet for vpc:{vpcId} and az:{availabilityZone}"; loggerProvider.GetLogger().Error(message); throw new Ec2ServiceException(message); } return privateSubnet.SubnetId; } }
public async Task<List<string>> GetPublicSubnetIdsAsync(string vpcId, List<string> availabilityZones) { using (var ec2Client = new AmazonEC2Client(credentials, ec2ConfigurationProvider.RegionEndpoint)) { var allSubnetsInMyVpcAndAz = await ec2Client.DescribeSubnetsAsync(new DescribeSubnetsRequest { Filters = new List<Filter> { new Filter {Name = "vpc-id", Values = new List<string> {vpcId}}, new Filter {Name = "availabilityZone", Values = availabilityZones} } }); var publicSubnets = allSubnetsInMyVpcAndAz.Subnets .Where(s => s.Tags.Any(t => string.Equals(t.Key, "AccessLevel", StringComparison.CurrentCultureIgnoreCase) && string.Equals(t.Value, "public", StringComparison.CurrentCultureIgnoreCase))) .ToList(); if (publicSubnets.IsNullOrEmpty()) { var message = $"Could not locate public subnet for vpc:{vpcId} and azs:{availabilityZones.Join(",")}"; loggerProvider.GetLogger().Error(message); throw new Ec2ServiceException(message); } return publicSubnets.Select(publicSubnet => publicSubnet.SubnetId).ToList(); } }