嘗試使用boto3自動部署靜態網站。我有一個靜態網站(angular/javascript/html)坐在一個桶中,並且需要使用aws cloudfront CDN。使用python部署帶有s3和cloudfront的靜態站點boto3
無論如何,看起來像使s3桶和複製在html/js工作正常。
import boto3
cf = boto3.client('cloudfront')
cf.create_distribution(DistributionConfig=dict(CallerReference='firstOne',
Aliases = dict(Quantity=1, Items=['mydomain.com']),
DefaultRootObject='index.html',
Comment='Test distribution',
Enabled=True,
Origins = dict(
Quantity = 1,
Items = [dict(
Id = '1',
DomainName='mydomain.com.s3.amazonaws.com')
]),
DefaultCacheBehavior = dict(
TargetOriginId = '1',
ViewerProtocolPolicy= 'redirect-to-https',
TrustedSigners = dict(Quantity=0, Enabled=False),
ForwardedValues=dict(
Cookies = {'Forward':'all'},
Headers = dict(Quantity=0),
QueryString=False,
QueryStringCacheKeys= dict(Quantity=0),
),
MinTTL=1000)
)
)
當我嘗試創建CloudFront的分佈,我得到以下錯誤:
InvalidOrigin: An error occurred (InvalidOrigin) when calling the CreateDistribution operation: The specified origin server does not exist or is not valid. An error occurred (InvalidOrigin) when calling the CreateDistribution operation: The specified origin server does not exist or is not valid.
有趣的是,它看起來是抱怨的起源,mydomain.com.s3.amazonaws.com,但是,當我在Web控制檯中爲s3存儲桶創建分配時,它對於相同的原始域名沒有問題。
更新: 我能得到這個與以下博託工作,但寧願使用boto3:
import boto
c = boto.connect_cloudfront()
origin = boto.cloudfront.origin.S3Origin('mydomain.com.s3.amazonaws.com')
distro = c.create_distribution(origin=origin, enabled=False, comment='My new Distribution')
嗯......不應該把'mydomain.com'當成桶名嗎?在桶名稱中不允許點... ...? – gsaslis
允許點和破折號。我確實嘗試了一個沒有'。'的桶名稱。字符,但我得到了同樣的錯誤。在aws Web控制檯中直接使用相同的Origin Domain Name字符串。 – Atifm
雖然存在嗎?我的意思是..你使用的域名實際上有效嗎? – gsaslis