本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或DescribeConfigRules
一起使用 CLI
以下代码示例演示如何使用 DescribeConfigRules
。
- CLI
-
- AWS CLI
-
获取 AWS Config 规则的详细信息
以下命令返回名为的 AWS Config 规则的详细信息
InstanceTypesAreT2micro
:aws configservice describe-config-rules --config-rule-names
InstanceTypesAreT2micro
输出:
{ "ConfigRules": [ { "ConfigRuleState": "ACTIVE", "Description": "Evaluates whether EC2 instances are the t2.micro type.", "ConfigRuleName": "InstanceTypesAreT2micro", "ConfigRuleArn": "arn:aws:config:us-east-1:123456789012:config-rule/config-rule-abcdef", "Source": { "Owner": "CUSTOM_LAMBDA", "SourceIdentifier": "arn:aws:lambda:us-east-1:123456789012:function:InstanceTypeCheck", "SourceDetails": [ { "EventSource": "aws.config", "MessageType": "ConfigurationItemChangeNotification" } ] }, "InputParameters": "{\"desiredInstanceType\":\"t2.micro\"}", "Scope": { "ComplianceResourceTypes": [ "AWS::EC2::Instance" ] }, "ConfigRuleId": "config-rule-abcdef" } ] }
-
有关API详细信息,请参阅 “DescribeConfigRules AWS CLI
命令参考”。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:此示例列出账户的配置规则以及选定属性。
Get-CFGConfigRule | Select-Object ConfigRuleName, ConfigRuleId, ConfigRuleArn, ConfigRuleState
输出:
ConfigRuleName ConfigRuleId ConfigRuleArn ConfigRuleState -------------- ------------ ------------- --------------- ALB_REDIRECTION_CHECK config-rule-12iyn3 arn:aws:config-service:eu-west-1:123456789012:config-rule/config-rule-12iyn3 ACTIVE access-keys-rotated config-rule-aospfr arn:aws:config-service:eu-west-1:123456789012:config-rule/config-rule-aospfr ACTIVE autoscaling-group-elb-healthcheck-required config-rule-cn1f2x arn:aws:config-service:eu-west-1:123456789012:config-rule/config-rule-cn1f2x ACTIVE
-
有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考DescribeConfigRules中的。
-
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 class ConfigWrapper: """ Encapsulates AWS Config functions. """ def __init__(self, config_client): """ :param config_client: A Boto3 AWS Config client. """ self.config_client = config_client def describe_config_rule(self, rule_name): """ Gets data for the specified rule. :param rule_name: The name of the rule to retrieve. :return: The rule data. """ try: response = self.config_client.describe_config_rules( ConfigRuleNames=[rule_name] ) rule = response["ConfigRules"] logger.info("Got data for rule %s.", rule_name) except ClientError: logger.exception("Couldn't get data for rule %s.", rule_name) raise else: return rule
-
有关API详细信息,请参阅DescribeConfigRules中的 AWS SDKPython (Boto3) API 参考。
-
有关 AWS SDK开发者指南和代码示例的完整列表,请参阅AWS Config 与 a 一起使用 AWS SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。
DescribeConfigRuleEvaluationStatus
DescribeConfigurationRecorderStatus