#119 cfmodify KeyError exception

Malfunction
open
nobody
s3cmd (118)
5
2013-02-19
2012-06-20
Jason Godfrey
No

I received the following when issuing the command s3cmd -d cfmodify --cf-default-root-object=index.html cf://E2OS6DVXC1IL0G

Problem: KeyError: 'Origin'
S3cmd: 1.1.0-beta3

Traceback (most recent call last):
File "./s3cmd", line 1800, in <module>
main()
File "./s3cmd", line 1741, in main
cmd_func(args)
File "/home/godfrey/s3cmd/s3cmd/S3/CloudFront.py", line 709, in modify
default_root_object = Cmd.options.cf_default_root_object)
File "/home/godfrey/s3cmd/s3cmd/S3/CloudFront.py", line 369, in ModifyDistribution
response = self.SetDistConfig(cfuri, dc, response['headers']['etag'])
File "/home/godfrey/s3cmd/s3cmd/S3/CloudFront.py", line 418, in SetDistConfig
request_body = str(dist_config)
File "/home/godfrey/s3cmd/s3cmd/S3/CloudFront.py", line 177, in __str__
appendXmlTextNode("Origin", self.info['Origin'], tree)
KeyError: 'Origin'

This was with the HEAD at 19a529adb90fe00d429e4847b58d4fd2d1dade36. When I fell back to commit 678159ce71d760137bd71a1859ec6cef34193dfc the command completed successfully, but the default root object was not changed.

(I reported this to the bug mailing list last night, but I don't see my email in the archive. To be safe I decided to open a bug.)

Discussion

  • Jason Godfrey
    Jason Godfrey
    2012-06-21

    The following patch seemed to clear it up for me.

    index 30050ca..e75988a 100644
    --- a/S3/CloudFront.py
    +++ b/S3/CloudFront.py
    @@ -133,7 +133,7 @@ class DistributionConfig(object):
    ## </Logging>
    ## </DistributionConfig>

    - EMPTY_CONFIG = "<DistributionConfig><Origin/><CallerReference/><Enabled>true</Enabled></DistributionConfig>"
    + EMPTY_CONFIG = "<DistributionConfig><S3Origin><DNSName/></S3Origin><CallerReference/><Enabled>true</Enabled></DistributionConfig>"
    xmlns = "http://cloudfront.amazonaws.com/doc/%(api_ver)s/" % { 'api_ver' : cloudfront_api_version }
    def __init__(self, xml = None, tree = None):
    if xml is None:
    @@ -174,7 +174,8 @@ class DistributionConfig(object):
    tree.attrib['xmlns'] = DistributionConfig.xmlns

    ## Retain the order of the following calls!
    - appendXmlTextNode("Origin", self.info['Origin'], tree)
    + s3org = appendXmlTextNode("S3Origin", '', tree)
    + appendXmlTextNode("DNSName", self.info['S3Origin']['DNSName'], s3org)
    appendXmlTextNode("CallerReference", self.info['CallerReference'], tree)
    for cname in self.info['CNAME']:
    appendXmlTextNode("CNAME", cname.lower(), tree)
    @@ -322,7 +323,7 @@ class CloudFront(object):
    def CreateDistribution(self, uri, cnames_add = [], comment = None, logging = None, default_root_object = None):
    dist_config = DistributionConfig()
    dist_config.info['Enabled'] = True
    - dist_config.info['Origin'] = uri.host_name()
    + dist_config.info['S3Origin']['DNSName'] = uri.host_name()
    dist_config.info['CallerReference'] = str(uri)
    dist_config.info['DefaultRootObject'] = default_root_object
    if comment == None:
    @@ -671,7 +672,7 @@ class Cmd(object):
    d = response['distribution']
    dc = d.info['DistributionConfig']
    output("Distribution created:")
    - pretty_output("Origin", S3UriS3.httpurl_to_s3uri(dc.info['Origin']))
    + pretty_output("Origin", S3UriS3.httpurl_to_s3uri(dc.info['S3Origin']['DNSName']))
    pretty_output("DistId", d.uri())
    pretty_output("DomainName", d.info['DomainName'])
    pretty_output("CNAMEs", ", ".join(dc.info['CNAME']))
    @@ -713,7 +714,7 @@ class Cmd(object):
    response = cf.GetDistInfo(cfuri)
    d = response['distribution']
    dc = d.info['DistributionConfig']
    - pretty_output("Origin", S3UriS3.httpurl_to_s3uri(dc.info['Origin']))
    + pretty_output("Origin", S3UriS3.httpurl_to_s3uri(dc.info['S3Origin']['DNSName']))
    pretty_output("DistId", d.uri())
    pretty_output("DomainName", d.info['DomainName'])
    pretty_output("Status", d.info['Status'])