'boto3 upload_file function error. cannot find the file
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marcin |
