I used the settings below to set variables enviroments on heroku dashboard:
heroku config:set BUCKET_NAME=(my bucket)
heroku config:set S3_KEY=(my access key)
heroku config:set S3_SECRET=(my secret access key)
In python:
import boto3
import os
s3 = boto3.resource('s3')
S3_BUCKET = os.environ.get('BUCKET_NAME')
S3_KEY = os.environ.get('AWS_ACCESS_KEY')
S3_SECRET = os.environ.get('AWS_SECRET_ACCESS_KEY')
The error occurs when entering the page where interaction with S3 is required. I've already done the config vars with the credentials, and even so, the error log shows the following messages:
File "/app/.heroku/python/lib/python3.10/site-packages/botocore/auth.py", line 407, in add_auth
raise NoCredentialsError()
botocore.exceptions.NoCredentialsError: Unable to locate credentials
these variables are taking the s3 credentials that I configured in the environment variables that are on my pc, the app is running normally locally.
below the forms of the call
init.py
client_s3 = boto3.client(
's3',
aws_access_key_id=S3_KEY,
aws_secret_access_key=S3_SECRET,
)
@app.route('/pasta-instrumento-usuario', methods=['GET', 'POST'])
def pasta_instrumento_usuario():
s3_resource = boto3.resource('s3')
my_bucket = s3_resource.Bucket(S3_BUCKET)
return render_template('pasta-instrumento-usuario.html', <br>my_bucket=my_bucket)