# Buggy code
def handle_BucketWebsiteConfiguration(self, resource, item_value):
    website = {}
    if item_value["indexDocumentSuffix"]:
        website["IndexDocument"] = {"Suffix": item_value["indexDocumentSuffix"]}
    if item_value["errorDocument"]:
        website["ErrorDocument"] = {"Key": item_value["errorDocument"]}
    if item_value["redirectAllRequestsTo"]:
        website["RedirectAllRequestsTo"] = {
            "HostName": item_value["redirectsAllRequestsTo"]["hostName"],
            "Protocol": item_value["redirectsAllRequestsTo"]["protocol"],
        }
    for r in item_value["routingRules"]:
        redirect = {}
        rule = {"Redirect": redirect}
        website.setdefault("RoutingRules", []).append(rule)
        if "condition" in r:
            cond = {}
            for ck, rk in (
                ("keyPrefixEquals", "KeyPrefixEquals"),
                ("httpErrorCodeReturnedEquals", "HttpErrorCodeReturnedEquals"),
            ):
                if r["condition"][ck]:
                    cond[rk] = r["condition"][ck]
            rule["Condition"] = cond
        for ck, rk in (
            ("protocol", "Protocol"),
            ("hostName", "HostName"),
            ("replaceKeyPrefixWith", "ReplaceKeyPrefixWith"),
            ("replaceKeyWith", "ReplaceKeyWith"),
            ("httpRedirectCode", "HttpRedirectCode"),
        ):
            if r["redirect"][ck]:
                redirect[rk] = r["redirect"][ck]
    resource["Website"] = website


# Traceback (KeyError)
2017-10-22 11:25:17,078: policyrun:DEBUG Running policy:blahblah account:acct1 region:us-east-1
2017-10-22 11:25:44,412: custodian.resources.s3:ERROR Exception getting resources from config
u'redirectsAllRequestsTo'
2017-10-22 11:25:44,414: custodian.output:ERROR Error while executing policy
Traceback (most recent call last):
File "/usr/local/custodian/site-packages/c7n/policy.py", line 305, in run
resources = self.policy.resource_manager.resources()
File "/usr/local/custodian/site-packages/c7n/query.py", line 395, in resources
resources = self.augment(self.source.resources(query))
File "/usr/local/custodian/site-packages/c7n/query.py", line 305, in resources
results.extend(f.result())
File "/usr/local/custodian/site-packages/concurrent/futures/_base.py", line 422, in result
return self.__get_result()
File "/usr/local/custodian/site-packages/concurrent/futures/thread.py", line 62, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/custodian/site-packages/c7n/query.py", line 271, in get_resources
results.append(self.load_resource(revisions[0]))
File "/usr/local/custodian/site-packages/c7n/resources/s3.py", line 152, in load_resource
method(resource, v)
File "/usr/local/custodian/site-packages/c7n/resources/s3.py", line 343, in handle_BucketWebsiteConfiguration
'HostName': item_value['redirectsAllRequestsTo']['hostName'],
KeyError: u'redirectsAllRequestsTo'

# Fixed code
def handle_BucketWebsiteConfiguration(self, resource, item_value):
    website = {}
    if item_value["indexDocumentSuffix"]:
        website["IndexDocument"] = {"Suffix": item_value["indexDocumentSuffix"]}
    if item_value["errorDocument"]:
        website["ErrorDocument"] = {"Key": item_value["errorDocument"]}
    if item_value["redirectAllRequestsTo"]:
        website["RedirectAllRequestsTo"] = {
            "HostName": item_value["redirectAllRequestsTo"]["hostName"],
            "Protocol": item_value["redirectAllRequestsTo"]["protocol"],
        }
    for r in item_value["routingRules"]:
        redirect = {}
        rule = {"Redirect": redirect}
        website.setdefault("RoutingRules", []).append(rule)
        if "condition" in r:
            cond = {}
            for ck, rk in (
                ("keyPrefixEquals", "KeyPrefixEquals"),
                ("httpErrorCodeReturnedEquals", "HttpErrorCodeReturnedEquals"),
            ):
                if r["condition"][ck]:
                    cond[rk] = r["condition"][ck]
            rule["Condition"] = cond
        for ck, rk in (
            ("protocol", "Protocol"),
            ("hostName", "HostName"),
            ("replaceKeyPrefixWith", "ReplaceKeyPrefixWith"),
            ("replaceKeyWith", "ReplaceKeyWith"),
            ("httpRedirectCode", "HttpRedirectCode"),
        ):
            if r["redirect"][ck]:
                redirect[rk] = r["redirect"][ck]
    resource["Website"] = website