使用 Amazon SDK 描述 Amazon Config 规则 - Amazon Config
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon SDK 描述 Amazon Config 规则

以下代码示例展示了如何描述 Amazon Config 规则。

CLI
Amazon CLI

获取 Amazon Config 规则的详细信息

以下命令返回名为的 Amazon 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" } ] }
Python
适用于 Python (Boto3) 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

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 的详细信息,请参阅适用DescribeConfigRulesPython 的 Amazon SDK (Boto3) API 参考

有关 S Amazon DK 开发者指南和代码示例的完整列表,请参阅Amazon Config 与 Amazon SDK 一起使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。