2017-06-21 35 views
0

我使用boto3與AWS S3通信。我第一次嘗試用我的本地系統。它成功地連接了並且工作正常。我提出的碼到服務器(燒瓶-apache2的)。現在代碼不起作用。這表明即使我設置的參數在~/.aws/credentialsProfileNotFound: The config profile (dev) could not be found例外,~/.aws/configAWS S3 - 沒有找出檔案信息

〜/ .aws /憑證文件:

[dev] 
aws_access_key_id = ***************** 
aws_secret_access_key = ********************* 

〜/ .aws /配置文件:

[default] 
region = us-west-2 
output = json 

[profile dev] 
region = us-west-2 
output = json 

這是怎麼了訪問配置文件:

session = boto3.Session(profile_name='dev') 
s3 = session.resource('s3') 

錯誤日誌:

session = boto3.Session(profile_name='dev') 
[Wed Jun 21 05:50:56.912720 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/boto3/session.py", line 80, in __init__ 
[Wed Jun 21 05:50:56.912836 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  self._setup_loader() 
[Wed Jun 21 05:50:56.912866 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/boto3/session.py", line 120, in _setup_loader 
[Wed Jun 21 05:50:56.912893 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  self._loader = self._session.get_component('data_loader') 
[Wed Jun 21 05:50:56.912910 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 701, in get_component 
[Wed Jun 21 05:50:56.913104 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  return self._components.get_component(name) 
[Wed Jun 21 05:50:56.913121 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 897, in get_component 
[Wed Jun 21 05:50:56.913134 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  self._components[name] = factory() 
[Wed Jun 21 05:50:56.913145 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 181, in <lambda> 
[Wed Jun 21 05:50:56.913154 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  lambda: create_loader(self.get_config_variable('data_path'))) 
[Wed Jun 21 05:50:56.913163 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 265, in get_config_variable 
[Wed Jun 21 05:50:56.913172 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  elif self._found_in_config_file(methods, var_config): 
[Wed Jun 21 05:50:56.913181 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 286, in _found_in_config_file 
[Wed Jun 21 05:50:56.913190 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  return var_config[0] in self.get_scoped_config() 
[Wed Jun 21 05:50:56.913198 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 358, in get_scoped_config 
[Wed Jun 21 05:50:56.913206 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564]  raise ProfileNotFound(profile=profile_name) 
[Wed Jun 21 05:50:56.913225 2017] [wsgi:error] [pid 21586] [remote 103.227.98.117:37564] ProfileNotFound: The config profile (dev) could not be found 
+0

最有可能的是在不同的用戶環境中運行它的憑據文件。 – helloV

+0

你能提出一些解決? – BBHeeMAA

回答

0

最後,我找到了解決辦法!

我將AWS Credentials &配置文件路徑添加到apache2 envvars文件。問題解決了。

步驟:

$sudo nano /etc/apache2/envvars 
    # Added the following lines 
    export AWS_CONFIG_FILE=/home/ubuntu/.aws/config 
    export AWS_SHARED_CREDENTIALS_FILE=/home/ubuntu/.aws/credentials 

sudo service apache2 reload | sudo service apache2 restart 

完成!它開始工作很好!

我開始嘗試添加像AWS_CONFIG_FILE=~/.aws/credentials這不起作用。必須給出完整的路徑。