0

I have an S3 bucket named gisat.. there is a folder named micro inside the bucket where I want the text file to be uploaded from my local machine. I'm running this using Pycharm. I don't know what the error is. Kinda new to boto3.

Here's the code:

import boto3    

def lambda_handler(event, context):
 s3_resource = boto3.resource('s3')

 mybucket = "gisat"

 s3_resource.Bucket(mybucket).upload_file("C:/Users/Acer/Desktop/new.txt", "micro/new.txt")

This is the error I get:

"errorMessage": "[Errno 2] No such file or directory: 'C:/Users/Acer/Desktop/new.txt'"

The path I have given is correct. But I don't know what the issue is.

I haven't established a connection between the local code and the AWS account though. Not exactly sure how to do it. Is that what's causing the error? Please help

1 Answer 1

0

Your code runs as a lambda function on AWS infrastructure, not your local computer. But your code, tries to read some local file from your windows computer (C:/Users/Acer/Desktop/new.txt), which obviously will not work.

You have to bundle new.txt with your lambda code if you want to use it in your function, or store it in S3 so that the function can read it before it uses it.

Finally, lambda environment is not windows, but it is based on Amazon Linux 2. So you have to use file paths that are valid in Linux, not Windows.

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

1 Comment

Actually, the plan was to upload the file to a folder inside s3 bucket using the local machine. Then read the contents of the folder and work on that using lambda.

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.