【问题标题】:How to export a resource name and use in different Cloudformation Stackset?如何导出资源名称并在不同的 Cloudformation Stackset 中使用?
【发布时间】:2020-11-16 06:12:40
【问题描述】:

我创建了一个将 AWS Config 规则部署到两个账户的 CloudFormation Stackset。现在我想创建一个部署补救措施的堆栈集。当我在一个 CFT 中拥有所有代码时,代码的底线就可以工作。但我想先在一个脚本中部署检测规则,然后再部署补救规则。如何从不同的 scipt 引用 S3BucketEncryptionEnabled 资源?

---------------------Detection --------------------------------------------------------
 S3BucketEncryptionEnabled:
    Type:  AWS::Config::ConfigRule
    Properties:
      Description: Checks that your Amazon S3 bucket either has S3 default encryption enabled or that the S3 bucket policy explicitly denies put-object requests without server side encryption.
      Source:
        Owner: AWS
        SourceIdentifier: S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED
      Scope:
        ComplianceResourceTypes:
          - AWS::S3::Bucket
    DependsOn: ConfigRecorder

----------------------Remediation Script-----------------------------------------------
BasicRemediationConfiguration:
    Type: "AWS::Config::RemediationConfiguration"
    Properties:
        Automatic: True
        MaximumAutomaticAttempts: 5
        RetryAttemptSeconds: 60
        ConfigRuleName: !Ref S3BucketEncryptionEnabled
        Parameters:
            AutomationAssumeRole:
                StaticValue:
                    Values: [{"Fn::GetAtt" : ["S3Role","Arn"]}]       
                    
            BucketName:
                ResourceValue:
                    Value: RESOURCE_ID


            SSEAlgorithm:
                StaticValue:
                    Values: [AES256]
        TargetId: "AWS-EnableS3BucketEncryption"
        TargetType: "SSM_DOCUMENT"
        TargetVersion: "1"

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    通常,在您的 Detection 模板中,您会在输出中使用 export S3BucketEncryptionEnabled

    例如:

    Outputs:
    
        S3BucketEncryptionEnabled:
            Value: !Ref S3BucketEncryptionEnabled
            Export:
                Name: MyS3BucketEncryptionEnabled
    

    然后在您的Remediation 模板中,您将使用ImportValue 来导入导出的值。

    例如:

    BasicRemediationConfiguration:
        Type: "AWS::Config::RemediationConfiguration"
        Properties:
            Automatic: True
            MaximumAutomaticAttempts: 5
            RetryAttemptSeconds: 60
            ConfigRuleName: !ImportValue MyS3BucketEncryptionEnabled
            # remaining properties
    

    【讨论】:

      猜你喜欢
      • 2017-01-15
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 2015-08-24
      • 2021-10-31
      • 2021-04-22
      • 2014-09-10
      • 1970-01-01
      相关资源
      最近更新 更多