文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DescribeConfigRules
搭配 a AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 DescribeConfigRules
。
- CLI
-
- AWS CLI
-
若要取得 Config AWS 規則的詳細資訊
下列命令會傳回名為 之 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 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeConfigRules
。
-
- PowerShell
-
- for 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
-
- Python 的 SDK (Boto3)
-
注意
還有更多 on 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 SDK for Python (Boto3) Word 參考中的 API。
-
DescribeConfigRuleEvaluationStatus
DescribeConfigurationRecorderStatus