AWS CloudFront不会对缓存命中收费,但是仍然需要支付数据传输和请求费用。在代码中,可以使用以下代码获取缓存命中信息,并确定是否降低实际成本:
import boto3
client = boto3.client('cloudfront')
response = client.get_distribution_metrics( DistributionId='E3EXAMPLE2YTZAB', StartTime='2020-07-01T00:00:00Z', EndTime='2020-07-31T23:59:59Z', Metrics=[ 'Requests', 'BytesDownloaded', 'BytesUploaded', 'BytesUploaded', 'TotalErrorRate', '4xxErrorRate', '5xxErrorRate', 'RequestsDenied' ], ByTime='DAILY', MaxItems='100' )
print(response)