2017-06-21 49 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这不起作用。必须给出完整的路径。