Hi I am a newbie in creating flask application, i have created a small GUI to upload files to the S3 Bucket Here is the code snippet which is handling the same
s3 = boto3.client('s3', region_name="eu-west-1",
endpoint_url=S3_LOCATION, aws_access_key_id=S3_KEY, aws_secret_access_key=S3_SECRET)
myclient = boto3.resource('s3')
file = request.files['file[]']
filename=file.filename
data_files = request.files.getlist('file[]')
for data_file in data_files:
file_contents = data_file.read()
ts = time.gmtime()
k=time.strftime("%Y-%m-%dT%H:%M:%S", ts)
name=filename[0:-4]
newfilename=(name+k+'.txt')
myclient.Bucket(S3_BUCKET).put_object(Key=newfilename,Body=file_contents)
message='File Uploaded Successfully'
print('upload Successful')
the part is working fine when I am testing it from my local system, but upon uploading it to the EC2 Instance,the part
myclient.Bucket(S3_BUCKET).put_object(Key=newfilename,Body=file_contents)
is where it is throwing the error:
botocore.exceptions.NoCredentialsError: Unable to locate credentials
I have created a file config.py where I am storing the all the credentials and passing them at runtime. Not sure what is Causing the Error at EC2 instance, please help me with it