Error Using DescribeSecurityGroupRulesRequest

1

I'm trying to get a list of security group rules and I'm getting an error.
There isn't much specific documentation on this topic, and I wasn't able to find any working examples. Here's my method, and the error is below.

        public DescribeSecurityGroupRulesResponse RulesList()
        {
            DescribeSecurityGroupRulesRequest request = new DescribeSecurityGroupRulesRequest();

            List<string> values = new List<string>();
            values.Add(GroupID);

            Amazon.EC2.Model.Filter FilterList = new Amazon.EC2.Model.Filter

            {
                Name = "group-id",
                Values = values
            };
            request.Filters.Add(FilterList);
            AmazonEC2Client eC2Client = new AmazonEC2Client(Credential, Region);
            DescribeSecurityGroupRulesResponse response = eC2Client.DescribeSecurityGroupRules(request);
            return response;
        }

ERROR: Amazon.EC2.AmazonEC2Exception: 'The request must contain the parameter AWSAccessKeyId'

已提问 1 年前291 查看次数
2 回答
1

Looking at the error, it says that while making the API call to list the rules of security group, the AWSAccessKeyId is missing. Access key id is mandatory while making API calls. I If you are using boto3, you can refer below link: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

As your requirement is to list the rules of security group, you can also use AWS CLI to list the security group rules. To configure AWS CLI for the same, please refer below link: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config

Once AWS configure is done, please rum below command to list the rules of Security group: aws ec2 describe-security-groups --group-ids sg-XXXXXX

Note: sg-XXXXXX is the security group name.

Below is the document for AWS CLI command reference for the API “describe-security-groups” : https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/describe-security-groups.html

Please ensure you have right set of credentials configured from the place you originate this call “aws configure list”

AWS
支持工程师
已回答 1 年前
  • Thanks for the reply, I didn't read the error close enough, but I got it worked out now.
    However, here's nothing that says how the request should be formatted, or even what the options are. I can see it takes a list of filters, and each filter has a name and value, but where is it written what those options are? Can you point me to something that shows the filter options?

1

As stated in the answer above, I also suspect that you're missing the credentials you need to make the API call. There are a number of ways that you can provide these credentials, including the shared credentials file, an environment variable, programmatically, SSO, etc. What method you use depends on the needs of your environment and application.

Since this post is tagged with .NET, the following are some sections from the .NET developer guide that discuss these topics:

Hope this helps.

AWS
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则