import uuid


def create_policy(accountid, s3bucket):
    """ Creates the S3 Bucket policy and grants access to the specified accounts with which the portfolio is being shared
    :param accountid: AWS account id
    :param s3bucket: S3 Bucket
    :return: Built S3 Policy Object
    """
    policy = {
        "Sid": str(uuid.uuid1()),
        "Effect": "Allow",
        "Principal": {
            "AWS": accountid
        },
        "Action": "s3:GetObject",
        "Resource": [
            "arn:aws:s3:::" + s3bucket + "/sc-templates/*"
        ]
    }
    return policy