How to get access to aws s3 calling the ListObjectsV2 operation in Python script

0 votes

Hi Guys,I try to get data from S3 AWS bucket. I set up bucket like public with bucket policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "*",
            "Resource": "arn:aws:s3:::transformed-for-visualization-data-1/*"
        }
    ]
}

In python script :

import boto3
from botocore import UNSIGNED
from botocore.client import Config

client = boto3.client('s3', config=Config(signature_version=UNSIGNED))
resource = boto3.client('s3', config=Config(signature_version=UNSIGNED))

for obj in client.list_objects_v2(Bucket='transformed-for-visualization-data-1', Prefix="csv/")['Contents']:
    print(obj['Key'])

after run it got an error:

ClientError: An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied
Where is mistake ?
Nov 25, 2021 in AWS by Yuriy
• 120 points
1,616 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

0 votes
1 answer

How to download the latest file in a S3 bucket using AWS CLI?

You can use the below command $ aws ...READ MORE

answered Sep 6, 2018 in AWS by Archana
• 4,170 points
19,819 views
0 votes
1 answer

how to access AWS S3 from Lambda in VPC

With boto3, the S3 urls are virtual by default, ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 58,100 points
10,091 views
0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 58,100 points
3,514 views
0 votes
1 answer

How to get the number of pages in a pdf file present in s3?

Hi@Manav, To know about information about pdf file, ...READ MORE

answered May 3, 2020 in AWS by MD
• 95,460 points
3,148 views
0 votes
1 answer

How to edit files in the AWS S3 bucket from CLI?

Hi@akhtar, According to my knowledge,  you can't edit ...READ MORE

answered Jun 8, 2020 in AWS by MD
• 95,460 points
9,647 views
0 votes
1 answer

how to get the list of aws services i am used in aws my account by using the lambda function

Hi@shalk, You can create a session in your ...READ MORE

answered Sep 24, 2020 in AWS by MD
• 95,460 points
2,440 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP