我在page的底部發現了類似於我所需要的代碼。如何使用boto和python3使CloudFront中的對象失效?
#!/usr/bin/env python3
from boto.cloudfront import CloudFrontConnection
aws_access_key = 'BJDJLSMQRWDSC4UPLS6S' # Not real
aws_secret_access_key = '8xRnWKxRR/93TeQv3pwzMNR222nwe5kjhYweCAij' # Not real
aws_cf_distribution_id = 'foobar35'
objects = [ '/index.html' ]
conn = CloudFrontConnection(aws_access_key, aws_secret_access_key)
print(conn.create_invalidation_request(aws_cf_distribution_id, objects))
當我運行它,我得到以下錯誤:
$ ./invalidate.py
Traceback (most recent call last):
File "./invalidate.py", line 14, in <module>
print(conn.create_invalidation_request(aws_cf_distribution_id, objects))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/boto/cloudfront/__init__.py", line 263, in create_invalidation_request
raise CloudFrontServerError(response.status, response.reason, body)
boto.cloudfront.exception.CloudFrontServerError: CloudFrontServerError: 404 Not Found
<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
<Error>
<Type>Sender</Type>
<Code>NoSuchDistribution</Code>
<Message>The specified distribution does not exist.</Message>
</Error>
<RequestId>343d3d5b-e269-11e5-bc96-eb9a228cf3e7</RequestId>
</ErrorResponse>
我認爲問題是,在那裏駐留/index.html我還沒有確定的S3桶。我有大約20個存儲桶,每個存儲桶都以URL的域名部分命名。我嘗試了各種排列,但無濟於事。
- S3://www.example.com.s3.amazonaws.com/index.html
- S3://www.example.com/index.html
- /www.example.com /index.html
- www.example.com/index.html
- /index.html
有人能告訴我如何得到這個工作?
謝謝你,弗拉德。你是對的,我不明白關於分配ID的部分。但是,對於我的角色而言,我還沒有訪問AWS Web Console的權限。你能告訴我如何使用Boto3創建一個發行版並獲得它的ID嗎? – rcrews
您需要使用'create_distribution()'方法。有關如何使用[這裏]的詳細說明(https://boto3.readthedocs.org/en/latest/reference/services/cloudfront.html#CloudFront.Client.create_distribution) –