Here is how I'm trying to list amazon (aws) security groups of VPC using AWSSDK in c#:
var ec2Client = new AmazonEC2Client(accessKey, secretKey, RegionEndpoint.USEast1);
var dsgRequest = new DescribeSecurityGroupsRequest();
var dsgResponse = ec2Client.DescribeSecurityGroups(dsgRequest);
List<SecurityGroup> mySGs = dsgResponse.SecurityGroups;
foreach (SecurityGroup item in mySGs)
{
Console.WriteLine("Existing security group: " + item.GroupId);
}
It only displays the default amazon security group while when I login to amazon via browser, I see lots of company security groups. Any idea why this does not list them all?
I think it's because you didn't set a RegionEndpoint
.
I modified your code slightly, and was able to enumerate my security groups:
var config = new AmazonEC2Config { RegionEndpoint = Amazon.RegionEndpoint.APSoutheast2};
var credentials = new BasicAWSCredentials(accessKey, secretKey);
using (var client = Amazon.AWSClientFactory.CreateAmazonEC2Client(credentials, config))
{
var dsgRequest = new DescribeSecurityGroupsRequest();
var dsgResponse = client.DescribeSecurityGroups(dsgRequest);
List<SecurityGroup> mySGs = dsgResponse.SecurityGroups;
foreach (SecurityGroup item in mySGs)
{
Console.WriteLine("Existing security group: " + item.GroupId);
}
}
Thanks for the help. I had actually set the end point properly. I ran the same code that I had a few days later and it worked. It must have been amazon services gone down or something like that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.