1

CloudTrail을 사용할 수있는 CloudFormation 스크립트를 만들고 새 S3 버킷을 생성하여 사용하거나 현재 사용중인 버킷을 사용할 수있는 옵션을 사용자에게 제공하려고합니다. S3 버킷. 나는 AWS를 처음 사용하기 때문에 조금 잃어 버렸습니다. 지금까지 조건문 등을 추가하지 않고서 찍은 수정 된 코드가 있습니다.AWS : Cloudformation 스크립트가 CloudTrail 용 S3 버킷을 조건부에 따라 작성합니다.

{ 
"AWSTemplateFormatVersion" : "2010-09-09", 
"Description" : "CloudTrail", 
"Parameters" : { 
    "UseExisitingBucket" : { 
     "Description" : "Yes/No", 
     "Default" : "Yes", 
     "Type" : "String", 
     "AllowedValues" : [ "yes", "no"] 
    }, 
    "BucketName" : { 
     "Description" : "Name of the S3 bucket.", 
     "Type" : "String" 
    }, 
    "TopicName" : { 
     "Description" : "Name of the SNS topic.", 
     "Type" : "String", 
     "Default" : "" 
    }, 
    "IncludeGlobalServiceEvents" : { 
     "Description" : "Indicates whether the trail is publishing events from global services, such as IAM, to the log files.", 
     "Type" : "String", 
     "Default" : "false", 
     "AllowedValues" : [ 
      "true", 
      "false" 
     ] 
    } 
}, 
"Conditions" : { 
    "UseSNSTopic" : { 
     "Fn::Not" : [ 
      { 
       "Fn::Equals" : [ 
        { 
         "Ref" : "TopicName" 
        }, 
        "" 
       ] 
      } 
     ] 
    } 
}, 
"Resources" : { 
    "Trail" : { 
     "Type" : "AWS::CloudTrail::Trail", 
     "Properties" : { 
      "IncludeGlobalServiceEvents" : { 
       "Ref" : "IncludeGlobalServiceEvents" 
      }, 
      "S3BucketName" : { 
       "Ref" : "BucketName" 
      }, 
      "SnsTopicName" : { 
       "Fn::If" : [ 
        "UseSNSTopic", 
        { 
         "Ref" : "TopicName" 
        }, 
        { 
         "Ref" : "AWS::NoValue" 
        } 
       ] 
      }, 
      "IsLogging" : true 
     } 
    } 
} 

}

답변

0

당신은 내가 제안 UseExisitingBucket 매개 변수를 제거 할 매우 가깝습니다.

"ExistingBucketName" : { 
    "Description" : "Name of the S3 bucket.", 
    "Type" : "String", 
    "Default": "None" 
}, 

추가 몇 가지 조건이 버킷이 제공되었는지 확인하거나 새로운 생성해야하는 경우 하나 :

"Conditions": { 
    "CreateNewBucket": { 
     "Fn::Equals": [ 
      { 
       "Ref": "ExistingBucketName" 
      }, 
      "None" 
     ] 
    }, 
    "UseExistingBucket": { 
     "Fn::Not": [ 
      { 
       "Fn::Equals": [ 
        { 
         "Ref": "ExistingBucketName" 
        }, 
        "None" 
       ]     
      } 
     ] 
    } 
} 

그런 S3 버킷 자원을 작성 그런 그래서 다음과 같이 보일 것 BucketNameDefault를 추가

"S3Bucket": { 
    "Condition": "CreateNewBucket", 
    ... 
    ... 

} 

"CreateNewBucket"조건으로 2 개의 cloudtrail 리소스 하나를 추가하고 "S3Bucket"조건을 전달하십시오. 리소스와 다른 하나는 "UseExistingBucket"을 사용하고 "ExistingBucketName"을 전달하십시오

+0

감사합니다. – flyingcars34