Question:
I want to create an empty file in AWS s3 using python.
I’m using boto3 and python.
I want to know apart from the put method is there any way to create files in s3?
Answer:
Assuming that you genuinely want a zero-byte file, you can do it as follows:
1 2 3 4 5 6 7 8 9 |
import boto3 s3 = boto3.client('s3') s3.put_object( Bucket='mybucket', Key='myemptyfile' ) |
Note the lack of a Body
parameter, resulting in an empty file.