karthick btech
karthick btech

Reputation: 63

how to create file in aws S3 using python boto3

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?

Upvotes: 5

Views: 10445

Answers (2)

jarmod
jarmod

Reputation: 78653

Assuming that you genuinely want a zero-byte file, you can do it as follows:

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.

Upvotes: 14

Srividya
Srividya

Reputation: 61

You can use upload_file() method :

s3_resource.Bucket(bucket_name).upload_file(Filename = "file_name" , Key = "key")

Upvotes: 1

Related Questions