OLD | NEW |
(Empty) | |
| 1 .. _cloudfront_tut: |
| 2 |
| 3 ========== |
| 4 CloudFront |
| 5 ========== |
| 6 |
| 7 This new boto module provides an interface to Amazon's Content Service, |
| 8 CloudFront. |
| 9 |
| 10 .. warning:: |
| 11 |
| 12 This module is not well tested. Paging of distributions is not yet |
| 13 supported. CNAME support is completely untested. Use with caution. |
| 14 Feedback and bug reports are greatly appreciated. |
| 15 |
| 16 Creating a CloudFront connection |
| 17 -------------------------------- |
| 18 If you've placed your credentials in your ``$HOME/.boto`` config file then you |
| 19 can simply create a CloudFront connection using:: |
| 20 |
| 21 >>> import boto |
| 22 >>> c = boto.connect_cloudfront() |
| 23 |
| 24 If you do not have this file you will need to specify your AWS access key and |
| 25 secret access key:: |
| 26 |
| 27 >>> import boto |
| 28 >>> c = boto.connect_cloudfront('your-aws-access-key-id', 'your-aws-secret-a
ccess-key') |
| 29 |
| 30 Working with CloudFront Distributions |
| 31 ------------------------------------- |
| 32 Create a new :class:`boto.cloudfront.distribution.Distribution`:: |
| 33 |
| 34 >>> distro = c.create_distribution(origin='mybucket.s3.amazonaws.com', enabl
ed=False, comment='My new Distribution') |
| 35 >>> d.domain_name |
| 36 u'd2oxf3980lnb8l.cloudfront.net' |
| 37 >>> d.id |
| 38 u'ECH69MOIW7613' |
| 39 >>> d.status |
| 40 u'InProgress' |
| 41 >>> d.config.comment |
| 42 u'My new distribution' |
| 43 >>> d.config.origin |
| 44 <S3Origin: mybucket.s3.amazonaws.com> |
| 45 >>> d.config.caller_reference |
| 46 u'31b8d9cf-a623-4a28-b062-a91856fac6d0' |
| 47 >>> d.config.enabled |
| 48 False |
| 49 |
| 50 Note that a new caller reference is created automatically, using |
| 51 uuid.uuid4(). The :class:`boto.cloudfront.distribution.Distribution`, |
| 52 :class:`boto.cloudfront.distribution.DistributionConfig` and |
| 53 :class:`boto.cloudfront.distribution.DistributionSummary` objects are defined |
| 54 in the :mod:`boto.cloudfront.distribution` module. |
| 55 |
| 56 To get a listing of all current distributions:: |
| 57 |
| 58 >>> rs = c.get_all_distributions() |
| 59 >>> rs |
| 60 [<boto.cloudfront.distribution.DistributionSummary instance at 0xe8d4e0>, |
| 61 <boto.cloudfront.distribution.DistributionSummary instance at 0xe8d788>] |
| 62 |
| 63 This returns a list of :class:`boto.cloudfront.distribution.DistributionSummary` |
| 64 objects. Note that paging is not yet supported! To get a |
| 65 :class:`boto.cloudfront.distribution.DistributionObject` from a |
| 66 :class:`boto.cloudfront.distribution.DistributionSummary` object:: |
| 67 |
| 68 >>> ds = rs[1] |
| 69 >>> distro = ds.get_distribution() |
| 70 >>> distro.domain_name |
| 71 u'd2oxf3980lnb8l.cloudfront.net' |
| 72 |
| 73 To change a property of a distribution object:: |
| 74 |
| 75 >>> distro.comment |
| 76 u'My new distribution' |
| 77 >>> distro.update(comment='This is a much better comment') |
| 78 >>> distro.comment |
| 79 'This is a much better comment' |
| 80 |
| 81 You can also enable/disable a distribution using the following |
| 82 convenience methods:: |
| 83 |
| 84 >>> distro.enable() # just calls distro.update(enabled=True) |
| 85 |
| 86 or:: |
| 87 |
| 88 >>> distro.disable() # just calls distro.update(enabled=False) |
| 89 |
| 90 The only attributes that can be updated for a Distribution are |
| 91 comment, enabled and cnames. |
| 92 |
| 93 To delete a :class:`boto.cloudfront.distribution.Distribution`:: |
| 94 |
| 95 >>> distro.delete() |
| 96 |
| 97 Invalidating CloudFront Distribution Paths |
| 98 ------------------------------------------ |
| 99 Invalidate a list of paths in a CloudFront distribution:: |
| 100 |
| 101 >>> paths = ['/path/to/file1.html', '/path/to/file2.html', ...] |
| 102 >>> inval_req = c.create_invalidation_request(u'ECH69MOIW7613', paths) |
| 103 >>> print inval_req |
| 104 <InvalidationBatch: IFCT7K03VUETK> |
| 105 >>> print inval_req.id |
| 106 u'IFCT7K03VUETK' |
| 107 >>> print inval_req.paths |
| 108 [u'/path/to/file1.html', u'/path/to/file2.html', ..] |
| 109 |
| 110 .. warning:: |
| 111 |
| 112 Each CloudFront invalidation request can only specify up to 1000 paths. If |
| 113 you need to invalidate more than 1000 paths you will need to split up the |
| 114 paths into groups of 1000 or less and create multiple invalidation requests. |
| 115 |
| 116 This will return a :class:`boto.cloudfront.invalidation.InvalidationBatch` |
| 117 object representing the invalidation request. You can also fetch a single |
| 118 invalidaton request for a given distribution using |
| 119 ``invalidation_request_status``:: |
| 120 |
| 121 >>> inval_req = c.invalidation_request_status(u'ECH69MOIW7613', u'IFCT7K03VU
ETK') |
| 122 >>> print inval_req |
| 123 <InvalidationBatch: IFCT7K03VUETK> |
| 124 |
| 125 The first parameter is the CloudFront distribution id the request belongs to |
| 126 and the second parameter is the invalidation request id. |
| 127 |
| 128 It's also possible to get *all* invalidations for a given CloudFront |
| 129 distribution:: |
| 130 |
| 131 >>> invals = c.get_invalidation_requests(u'ECH69MOIW7613') |
| 132 >>> print invals |
| 133 <boto.cloudfront.invalidation.InvalidationListResultSet instance at 0x15d28d
0> |
| 134 |
| 135 This will return an instance of |
| 136 :class:`boto.cloudfront.invalidation.InvalidationListResultSet` which is an |
| 137 iterable object that contains a list of |
| 138 :class:`boto.cloudfront.invalidation.InvalidationSummary` objects that describe |
| 139 each invalidation request and its status:: |
| 140 |
| 141 >>> for inval in invals: |
| 142 >>> print 'Object: %s, ID: %s, Status: %s' % (inval, inval.id, inval.sta
tus) |
| 143 Object: <InvalidationSummary: ICXT2K02SUETK>, ID: ICXT2K02SUETK, Status: Com
pleted |
| 144 Object: <InvalidationSummary: ITV9SV0PDNY1Y>, ID: ITV9SV0PDNY1Y, Status: Com
pleted |
| 145 Object: <InvalidationSummary: I1X3F6N0PLGJN5>, ID: I1X3F6N0PLGJN5, Status: C
ompleted |
| 146 Object: <InvalidationSummary: I1F3G9N0ZLGKN2>, ID: I1F3G9N0ZLGKN2, Status: C
ompleted |
| 147 ... |
| 148 |
| 149 Simply iterating over the |
| 150 :class:`boto.cloudfront.invalidation.InvalidationListResultSet` object will |
| 151 automatically paginate the results on-the-fly as needed by repeatedly |
| 152 requesting more results from CloudFront until there are none left. |
| 153 |
| 154 If you wish to paginate the results manually you can do so by specifying the |
| 155 ``max_items`` option when calling ``get_invalidation_requests``:: |
| 156 |
| 157 >>> invals = c.get_invalidation_requests(u'ECH69MOIW7613', max_items=2) |
| 158 >>> print len(list(invals)) |
| 159 2 |
| 160 >>> for inval in invals: |
| 161 >>> print 'Object: %s, ID: %s, Status: %s' % (inval, inval.id, inval.sta
tus) |
| 162 Object: <InvalidationSummary: ICXT2K02SUETK>, ID: ICXT2K02SUETK, Status: Com
pleted |
| 163 Object: <InvalidationSummary: ITV9SV0PDNY1Y>, ID: ITV9SV0PDNY1Y, Status: Com
pleted |
| 164 |
| 165 In this case, iterating over the |
| 166 :class:`boto.cloudfront.invalidation.InvalidationListResultSet` object will |
| 167 *only* make a single request to CloudFront and *only* ``max_items`` |
| 168 invalidation requests are returned by the iterator. To get the next "page" of |
| 169 results pass the ``next_marker`` attribute of the previous |
| 170 :class:`boto.cloudfront.invalidation.InvalidationListResultSet` object as the |
| 171 ``marker`` option to the next call to ``get_invalidation_requests``:: |
| 172 |
| 173 >>> invals = c.get_invalidation_requests(u'ECH69MOIW7613', max_items=10, mar
ker=invals.next_marker) |
| 174 >>> print len(list(invals)) |
| 175 2 |
| 176 >>> for inval in invals: |
| 177 >>> print 'Object: %s, ID: %s, Status: %s' % (inval, inval.id, inval.sta
tus) |
| 178 Object: <InvalidationSummary: I1X3F6N0PLGJN5>, ID: I1X3F6N0PLGJN5, Status: C
ompleted |
| 179 Object: <InvalidationSummary: I1F3G9N0ZLGKN2>, ID: I1F3G9N0ZLGKN2, Status: C
ompleted |
| 180 |
| 181 You can get the :class:`boto.cloudfront.invalidation.InvalidationBatch` object |
| 182 representing the invalidation request pointed to by a |
| 183 :class:`boto.cloudfront.invalidation.InvalidationSummary` object using:: |
| 184 |
| 185 >>> inval_req = inval.get_invalidation_request() |
| 186 >>> print inval_req |
| 187 <InvalidationBatch: IFCT7K03VUETK> |
| 188 |
| 189 Simiarly you can get the parent |
| 190 :class:`boto.cloudfront.distribution.Distribution` object for the invalidation |
| 191 request from a :class:`boto.cloudfront.invalidation.InvalidationSummary` object |
| 192 using:: |
| 193 |
| 194 >>> dist = inval.get_distribution() |
| 195 >>> print dist |
| 196 <boto.cloudfront.distribution.Distribution instance at 0x304a7e8> |
OLD | NEW |