【问题标题】:forbidden from sending request to cloudfront endpoint禁止向云端端点发送请求
【发布时间】:2014-11-12 08:34:05
【问题描述】:

我正在尝试向我的云端分配发送一个失效批次。这是我的做法:

import requests
import datetime
from tinys3.auth import S3Auth

date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
host = 'cloudfront.amazonaws.com'
path = '/2014-10-21/distribution/%s/invalidation' % DIST_ID

auth = S3Auth(s3key, s3secret)
# I'm assuming the authorization for s3 takes the same form as the auth for cloudfront.

file_path = 'path/to/file'

data = ['<?xml version="1.0" encoding="UTF-8"?>']
data.append('<InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/2014-10-21/">')
data.append('<Paths><Quantity>1</Quantity><Items><Path>/%s</Path></Items></Paths>' % file_path)
data.append('<CallerReference>%s</CallerReference>' % date)
data.append('</InvalidationBatch>')
data = ''.join(data)

try:
    url = 'https://%s%s' % (host, path)
    r = requests.post(url, data=data, headers=headers, auth=auth)
    r.raise_for_status()
    print 'Success?'
except:
    raise

如您所见,我正在使用来自 tinys3.py 和 cloudfront api 的授权协议。你可以在这里和这里找到他们的文档:

https://github.com/smore-inc/tinys3

http://docs.aws.amazon.com/AmazonCloudFront/latest/APIReference/CreateInvalidation.html

当我发出 POST 请求时,我得到一个 403。但我确信我的分发 ID 是有效的(我可以通过 cloudfront GUI 使用它)。我做错了什么?

【问题讨论】:

    标签: python amazon-web-services amazon-cloudfront


    【解决方案1】:

    我一直在使用 boto 进行 CloudFront 失效。带有 boto 的 Python 代码如下所示:

    import boto
    
    cfcon = boto.connect_cloudfront('your-aws-access-key-id', 'your-aws-secret-access-key')
    files = [<your files>]
    cfcon.create_invalidation_request(DIST_ID, files)
    

    【讨论】:

    • 谢谢,成功了。我更感兴趣的是弄清楚如何在不通过 boto 的情况下访问 cloudfront。使用 boto 意味着依赖于 python。
    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 2021-11-17
    • 2020-09-30
    • 2019-09-08
    相关资源
    最近更新 更多