2013-12-17 18 views
15

बनाने के लिए स्क्रिप्ट का उपयोग करके बाल्टी और वितरण के एडब्ल्यूएस निर्माण पर काम कर रहा हूं। मैंने एक स्क्रिप्ट बनाई है और AWS क्लाउड गठन कंसोल में स्टैक टेम्पलेट स्क्रिप्ट चला रहा है।एडब्ल्यूएस - क्लाउड गठन स्क्रिप्ट एस 3 बाल्टी और वितरण

मैं स्क्रिप्ट और कैननिकल आईडी का उपयोग कर एस 3 बाल्टी के लिए बाल्टीपोलिसी बना रहा हूं। एक बार जब मैं बाल्टी नीति बनाता हूं तो मैं इसे स्क्रिप्ट में गतिशील रूप से "OriginAccessIdentity" को असाइन करना चाहता हूं। मैं बाल्टी नीति से उत्पन्न उत्पत्ति को "OriginAccessIdentity" विशेषताओं में जोड़ना चाहता हूं।

इस कार्यक्षमता को कैसे प्राप्त करें?

स्क्रिप्ट:

{ 
    "AWSTemplateFormatVersion" : "2010-09-09", 

    "Description" : "AWS CloudFormation Template S3_With_CloudFront_Distribution", 

    "Parameters" : { 
     "bucketname" : { 
      "Type" : "String", 
      "Description" : "test"   
     }, 

     "cannonicalid" : { 
      "Type" : "String", 
      "Description" : "234213523145314534523452345234523452345"  
     } 
    }, 

    "Conditions" : { 
     "CreateProdResources" : {"Fn::Equals" : [{"Ref" : "EnvType"}, "dev"]} 
    }, 

    "Resources" : { 
     "testbucket" : { 
      "Type" : "AWS::S3::Bucket", 
      "Properties" : {  
      "BucketName" : { "Ref" : "bucketname" },   
      "WebsiteConfiguration" : { 
       "IndexDocument" : "index.html"    
      } 
      } 
     }, 


     "mybucketpolicy" : { 
      "Type" : "AWS::S3::BucketPolicy", 
      "Properties" : { 
       "PolicyDocument" : { 
       "Id" : "MyPolicy", 
       "Statement" : [ { 
        "Sid" : "Grant a CloudFront Origin Identity access to support private content", 
        "Action" : [ "s3:GetObject" ], 
        "Effect" : "Allow", 
        "Resource" : { "Fn::Join" : [ 
          "", [ "arn:aws:s3:::", { "Ref" : "testbucket" } , "/*" ] 
         ] }, 
        "Principal" : { 
         "CanonicalUser":{ "Ref" : "cannonicalid" } 
        } 
       } ] 
       }, 
       "Bucket" : { "Ref" : "testbucket" } 
       } 
     }, 


     "testdistribution" : { 
      "Type" : "AWS::CloudFront::Distribution", 
      "Properties" : { 
       "DistributionConfig" : { 
        "Origins" : [ { 
          "Id" : "S3Origin", 
          "DomainName" : { "Fn::GetAtt" : [ "testbucket", "DomainName" ] }, 
          "S3OriginConfig" : { 
           "OriginAccessIdentity" : "How to configure the id dynamically here" 
          } 
         } 
        ], 

        "Enabled" : "true", 
        "Comment" : "", 
        "DefaultRootObject" : "index.html",      
        "Aliases" : [ "test.com" ], 

        "CacheBehaviors" : [ { 
          "TargetOriginId" : "S3Origin", 
          "ForwardedValues" : { 
           "QueryString" : "false" 
          },        
          "ViewerProtocolPolicy" : "allow-all", 
          "MinTTL" : "1", 
          "PathPattern" : "resources/*.json" 
         } 
        ], 
        "DefaultCacheBehavior" : { 
         "TargetOriginId" : "S3Origin", 
         "ForwardedValues" : { 
          "QueryString" : "false" 
         },      
         "ViewerProtocolPolicy" : "allow-all", 
         "MinTTL" : "1" 
        } 
       } 
      } 
     } 
    }, 
    "Outputs" : { 
     "DistributionId" : { 
      "Description" : "CloudFront Distribution Id", 
      "Value" : { "Ref" : "testdistribution" } 
     }, 
     "DistributionName" : { 
      "Description" : "URL to access the CloudFront distribution", 
      "Value" : { "Fn::Join" : [ "", ["http://", {"Fn::GetAtt" : ["testdistribution", "DomainName"]} ]]} 
     }, 
     "S3OriginDNSName" : { 
      "Description" : "Name of S3 bucket to hold website content.", 
      "Value" : { "Fn::GetAtt" : [ "testbucket", "DomainName"] } 
     } 
    } 
} 
+0

बादल गठन में एक OAI उपयोगकर्ता बनाने के लिए स्क्रिप्ट अपने उचित नहीं का उपयोग करना

एक मूल पहुँच पहचान संसाधन के साथ

के रूप में परिभाषित , कारण क्लाउड में उपयोगकर्ता बनाने में थोड़ा समय लग सकता है। इसलिए हम .NET कोड का उपयोग कर ओएआई उपयोगकर्ता बना रहे हैं, फिर स्क्रिप्ट में ओएआई उपयोगकर्ता का उपयोग कर रहे हैं। ओएआई उपयोगकर्ता के निर्माण के लिए कोई अन्य बेहतर समाधान है तो कृपया मुझे बताएं। –

+0

.NET कोड का उपयोग कर ओएआई बनाने के लिए यूआरएल देखें। http://irfanshirur.blogspot.in/2014/01/create-oai-and-canonical-user-using-net.html –

उत्तर

6

एक उत्पत्ति पहुँच पहचान CloudFormation के साथ नहीं बनाया जा सकता है। क्लाउडफॉर्मेशन के माध्यम से उपलब्ध क्लाउडफ्रंट संसाधन AWS::CloudFront::Distribution संसाधन है।

जब आप अपना स्टैक बनाते हैं तो मौजूदा ओएआई में पास करने के लिए पैरामीटर का उपयोग करके आप अपने टेम्पलेट में ओएआई के संदर्भ को हार्ड कोडिंग से बच सकते हैं। S3OriginConfig कुंजी से जुड़े S3Origin प्रकार में आप OriginAccessIdentity के मान के रूप में इस पैरामीटर का उपयोग कर सकते हैं।

यह आदर्श नहीं है, लेकिन यह आपको अपने टेम्पलेट्स को अधिक सामान्य बनाने की अनुमति देता है।

2

2 नवंबर, 2017 के बाद से क्लाउडफॉर्मेशन एडब्लूएस :: क्लाउडफ्रंट :: क्लाउडफ्रंटऑरिगिनएक्सआईडेंटिटी संसाधन का उपयोग करके इसका समर्थन करता है।

"OriginAccessId": { 
    "Type": "AWS::CloudFront::CloudFrontOriginAccessIdentity", 
    "Properties": { 
     "CloudFrontOriginAccessIdentityConfig": { 
      "Comment": "MyDescription" 
     } 
    } 
} 

आप इसके साथ वितरण config में देख सकते हैं:

"OriginAccessIdentity" : { 
    "Fn::Sub": "origin-access-identity/cloudfront/${OriginAccessId}" 
} 
संबंधित मुद्दे