-1

i have set the config variable using the following code

heroku config:set --app xxxxxx S3_KEY=XXXXXXXXXXXXXXX S3_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXX S3_BUCKET =XXXXXXXXXXXX

got the following reply:

Setting S3_KEY, S3_SECRET_ACCESS_KEY, S3_BUCKET and restarting ⬢ xxxx... done, v46
S3_BUCKET:            XXXXXXXXX
S3_KEY:               XXXXXXXXXXXXXX
S3_SECRET_ACCESS_KEY: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

here is my helper.py function where i set the boto3 client:

import boto3, botocore
from config import S3_KEY, S3_SECRET, S3_BUCKET
import os
s3 = boto3.client(
   "s3",
   region_name='us-east-1',
   aws_access_key_id=os.environ['S3_KEY'],
   aws_secret_access_key=os.environ['S3_SECRET_ACCESS_KEY']
)
s3Res = boto3.resource('s3', region_name='us-east-1')

but it is not working, i keep getting the error :

botocore.exceptions.NoCredentialsError: Unable to locate credentials

what am i doing wrong? how can i get s3 to work with my heroku flask app?

AynonT
  • 225
  • 5
  • 13

1 Answers1

2

I use it similarly and it works.

import boto3
from config import Config
_client = boto3.client('s3',
                       aws_access_key_id=Config.AWS_ACCESS_KEY_ID,
                       aws_secret_access_key=Config.AWS_SECRET_ACCESS_KEY,
                       region_name=Config.AWS_REGION)
_BUCKET_NAME = Config.AWS_BUCKET_NAME
s3 = boto3.resource('s3')

You can check in AmazonCli if the values are corrects, and also look at that other question.

Obs.: config is a module with environment variables.

Angelo Mendes
  • 905
  • 13
  • 24
  • The keys are in ```~/.aws/credentials``` like, shown in https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#interactive-configuration? – Angelo Mendes Apr 16 '19 at 01:21
  • Thank you guys, i was using the wrong key. got it all working now. Thank you very much – AynonT Apr 16 '19 at 02:19