[英]Can't deploy a config rule through the CDK
我正在通過利用適用於 AWS 的 Python CDK 在我的組織中應用配置規則。 在我的設置中,我有一個來自此處的托管配置規則列表。 此列表位於將通過堆棧集進一步部署的堆棧中。 我對一致性包中的一些配置規則有疑問。 出於某種原因,cloudformation 不接受SourceIdentifier: AWS_CONFIG_PROCESS_CHECK
from aws_cdk import (
core as cdk,
aws_config as config,
)
....
class TestConfigRulesStack(cdk.Stack):
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
self.rule = config.ManagedRule(
self,
'ManagedRule-test',
config_rule_name='account-contact-details-configured',
identifier='AWS_CONFIG_PROCESS_CHECK',
)
....
錯誤:
The sourceIdentifier AWS_CONFIG_PROCESS_CHECK is invalid. Please refer to the documentation for a list of valid sourceIdentifiers that can be used when AWS is the Owner. (Service: AmazonConfig; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: <request_id>; Proxy: null)
CDK output:
...
"JSIIMetaManagedRuleaccountcontactdetailsconfigured9BA14D66": {
"Type": "AWS::Config::ConfigRule",
"Properties": {
"Source": {
"Owner": "AWS",
"SourceIdentifier": "AWS_CONFIG_PROCESS_CHECK"
},
"ConfigRuleName": "account-contact-details-configured",
"Description": "Ensure the contact email and telephone number for AWS accounts are current and map to more than one individual in your organization. Within the My Account section of the console ensure correct information is specified in the Contact Information section."
},
"Metadata": {
"aws:cdk:path": "<path>"
}
},
...
這是官方模板中的配置規則:
AccountContactDetailsConfigured:
Properties:
ConfigRuleName: account-contact-details-configured
Description: Ensure the contact email and telephone number for AWS accounts are current and map to more than one individual in your organization. Within the My Account section of the console ensure correct information is specified in the Contact Information section.
Source:
Owner: AWS
SourceIdentifier: AWS_CONFIG_PROCESS_CHECK
Type: AWS::Config::ConfigRule
我錯過了什么嗎? 我不明白為什么它不起作用。
要使用默認的 AWS 托管規則,您只需使用位於aws_cdk.aws_config.ManagedRuleIdentifiers
中的常量來附加該規則。 您不需要使用 from_config 或任何其他 from 功能導入規則。
只要您使用規則作為一部分的構造采用 iRule,您就可以使用aws_cdk.aws_config.ManagedRuleIdentifiers.THE_NAME_OF_THE_RULE
或者,基於您的進口
config.ManagedRuleIdentifiers.THE_NAME_OF_THE_RULE
您可以在此處獲取 AWS 托管規則列表及其常量值:
https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_config/ManagedRuleIdentifiers.html
如果它不是 AWS 托管規則,並且您已經通過另一種方法(另一個堆棧,手動,另一個 cloudformation 模板)創建了它,那么您需要使用 from_ 功能將它導入到這個堆棧中。
如果它是在另一個 CDK 堆棧中創建的,您可以從該堆棧中公開它並將其用作您需要它的任何其他堆棧中的參數,但我建議您將它們全部設為 nestedStacks 並將它們放在一個通用應用程序下,這樣您就不會沒有部署依賴性問題
您正在使用與現有 AWS 擁有的 ManagedRule 相同的標識符創建新規則。
要導入現有規則而不是創建新規則,請使用ManagedRule.fromConfigRuleName
:
rule = config.ManagedRule.from_config_rule_name(
self,
'ManagedRule-test',
config_rule_name='account-contact-details-configured'
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.