2

I need to upload a csv diretly to AWS S3 with public access.

My current code is:

import boto3

s3 = boto3.resource('s3', aws_access_key_id='xxx', aws_secret_access_key='yyy')
s3.Bucket('test1234542').upload_file('C:/Users/output1.csv', 'output1.csv')

Unfortunately the permission is private and i dont know who to change to code to upload it with public access directly.

At the moment i have to go manually to the bucket, click on the folder "Permissions",click on "Public Access" and then make a tick at "Read object".

Does someone know a python code to add the public access permission?

Best Michi

3 Answers 3

1

When you upload a file in AWS S3, by default its private.

In order to give public access to the file, first change the public access options of the bucket to allow the changes made to its objects.

change public access settings of the bucket

code to upload file with public access :

import boto3
s3 = boto3.resource('s3')
s3.Bucket('bucket_name').upload_file('data.csv', 'data.csv')
file_object = s3.Bucket('bucket_name').Object('data.csv')
print(file_object.Acl().put(ACL = 'public-read'))

Hope It helps !!

Sign up to request clarification or add additional context in comments.

Comments

0

You could use this to make the S3 bucket public. Make sure your EC2 instance has the correct instance-profile attached and it has the correct permissions to interact with S3( Possible s3 full access). Use the following link and let me know if it helps!

S3 Bucket Access Public

3 Comments

Hi. Thanks for your feedback. Unfortunately, I am not able to put that in python form. Can you maybe provide me a python code? Best
Are you running the python script from the CLI of the EC2 instance ?
I run the python script from the CLI by the command prompt. The program starts if i type "python merge_stock.py"
0

Provide the ACL argument in your put_object statement and the uploaded object will be public. Refer to this documentation.

client.put_object(
                  ACL='public-read',
                  Body='file that is to be uploaded',
                  Bucket='name of the bucket',
                  Key='obejct key'
                  )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.