'Remove obsolete policy statements to prevent policy from bloating over the limit after repeated updates.'

def _clear_policy(self, lambda_name):

    try:
        policy_response = self.lambda_client.get_policy(FunctionName=lambda_name)
        if (policy_response['ResponseMetadata']['HTTPStatusCode'] == 200):
            statement = json.loads(policy_response['Policy'])['Statement']
            for s in statement:
                delete_response = self.lambda_client.remove_permission(FunctionName=lambda_name, StatementId=s['Sid'])
                if (delete_response['ResponseMetadata']['HTTPStatusCode'] != 204):
                    logger.error('Failed    to    delete    an    obsolete    policy    statement:    {}'.format())
        else:
            logger.debug('Failed    to    load    Lambda    function    policy:    {}'.format(policy_response))
    except ClientError as e:
        if (e.args[0].find('ResourceNotFoundException') > (-1)):
            logger.debug('No    policy    found,    must    be    first    run.')
        else:
            logger.error('Unexpected    client    error    {}'.format(e.args[0]))
