import json


def s3_create_anon_access_policy(bucket_name):
    """Create a bucket policy for anonymous read access and anonymous bucket listing.
    Returns
    -------
    anon_access_policy: A json formatted s3 bucket policy
    """
    anon_policy_dict = {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "AddPerm",
                "Effect": "Allow",
                "Principal": "*",
                "Action": ["s3:GetObject"],
                "Resource": ["arn:aws:s3:::%s/*" % bucket_name]
            },
            {
                 "Sid": "AddPerm",
                 "Effect": "Allow",
                 "Principal": "*",
                 "Action": ["s3:ListBucket"],
                 "Resource": ["arn:aws:s3:::%s" % bucket_name]
            }
        ]
    }
    anon_access_policy = json.dumps(anon_policy_dict)
    return anon_access_policy