简体   繁体   English

AWS-S3-GetBucketPolicy

[英]AWS - S3 - GetBucketPolicy

Having trouble understanding just why my get_bucket_policy function is not working. 无法理解为什么我的get_bucket_policy函数不起作用。 i have double checked for typos and I have a policy and I get this error: 我已经仔细检查过错别字,并且有一项政策,但出现此错误:

An error occurred (NoSuchBucketPolicy) when calling the GetBucketPolicy operation: The bucket policy does not exist

from this script: 从此脚本:

import boto3
import json

BUCKET_NAME ='patrick-s3-2018-bucket'

def s3_client():
    s3 = boto3.client('s3')
    """:type : pyboto3.s3"""
    return s3

def create_bucket(bucket_name):
    return s3_client().create_bucket(
        Bucket=bucket_name,
        CreateBucketConfiguration={
            'LocationConstraint': 'us-east-2'
            }
        )

def create_bucket_policy():
    bucket_policy = {
        "Version": "2012-10-17",
        "Statement":[
            {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action":["s3:*"],
            "Resource":["arn:aws:s3:::patricksbucket/*"]
            }
        ]
    }
    policy_string = json.dumps(bucket_policy)

    return s3_client().put_bucket_policy(
        Bucket=BUCKET_NAME,
        Policy=policy_string
    )
def list_buckets():
    return s3_client().list_buckets()

def get_bucket_policy():
    return s3_client().get_bucket_policy(Bucket=BUCKET_NAME)


if __name__ == '__main__':
    print(get_bucket_policy())

I have also tried to use the full actual bucket name , not just the variable but this has not solved the issue. 我还尝试使用完整的实际存储桶名称,而不仅仅是变量,但这并没有解决问题。

This issue does not appear to be well documented online, when using AWS resources it is hard for me to compare their examples to the UDEMY class example I am using as I am still learning 在网上似乎没有很好地记录此问题,使用AWS资源时,我很难将其示例与我正在使用的UDEMY类示例进行比较,因为我仍在学习

All, 所有,

Answer to my own questions: 回答我自己的问题:

First error: my "Resource":["arn:aws:s3:::patricksbucket/*"] , was different than BUCKET_NAME ='patrick-s3-2018-bucket' Second Error: I needed to create_bucket 第一个错误:我的"Resource":["arn:aws:s3:::patricksbucket/*"]不同于BUCKET_NAME ='patrick-s3-2018-bucket'第二个错误:我需要create_bucket

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM