我使用CfnInclude将cloudformation模板导入到我的cdk代码中:
template= _cfn_include.CfnInclude(self,
     'template',
      template_file = "aws-waf-security-automations.yaml")在那之后,我使用get_resource()从这个模板中获得了一个资源:
waf = template.get_resource("WebACLStack")问题是这个资源的类型不是WafWebACL,而是CfnStack。在模板内部,这个资源是这样描述的:
WebACLStack:
Type: 'AWS::CloudFormation::Stack'
DependsOn: CheckRequirements
Properties:
  TemplateURL: !Sub
    - 'https://${S3Bucket}.s3.amazonaws.com/${KeyPrefix}/aws-waf-security-automations-webacl.template'
    -
      S3Bucket: !FindInMap ["SourceCode", "General", "TemplateBucket"]
      KeyPrefix: !FindInMap ["SourceCode", "General", "KeyPrefix"]
  Parameters:
    ActivateAWSManagedRulesParam: !Ref ActivateAWSManagedRulesParam ...如何从CfnStack中取出WAFWebACL?据我所知,WAFWebACL是CfnStack中的一个嵌套堆栈。
Obs:我从这个url得到了这个模板:https://docs.aws.amazon.com/solutions/latest/aws-waf-security-automations/template.html
Obs2:模板输出如下:
 WAFWebACL:
   Description: AWS WAF WebACL
   Value: !GetAtt WebACLStack.Outputs.WAFWebACL那么,我可以从输入中获取WAFWebACL资源吗?
发布于 2021-08-28 13:59:12
您需要先加载嵌套的堆栈:
from aws_cdk.aws_wafv2 import CfnWebACL
web_acl_stack = template.load_nested_stack("WebACLStack", template_file="aws-waf-security-automations-webacl.template")
waf: CfnWebACL = web_acl_stack.get_resource("WAFWebACL")我认为您还需要在本地保留嵌套堆栈的堆栈模板,并在加载嵌套堆栈时使用正确的路径,而不仅仅是"aws-waf-security-automations-webacl.template“。
(我假设您使用的是Python)
https://stackoverflow.com/questions/68955406
复制相似问题