I have an S3 bucket called source-bucket-6
and I write a lambda function to copy files from the lambda location to the S3 bucket.
As you see in the screenshot, here we have two files Index.html
and Test.txt
. I just want to copy those files to the S3 bucket. But whenever I try to copy them to the bucket, I see both files are empty and there’s no content in the files. Here’s my lambda code:
import boto3
import os
s3 = boto3.client('s3')
cwd = os.getcwd()
def lambda_handler(event, context):
bucket = 'source-bucket-6'
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
if f != "lambda_function.py":
s3.put_object(Bucket=bucket, Key=f)
print(f"------------------{f} ")
print("Put Completed")
2
Answers
Your
put_object
command is not specifying any content for the object.If you want to upload a file, use:
where
f
is the filename of the file to upload.You are missing Body argument. It should be: