yanchuen 发表于 2019-2-22 09:17:04

AWS SDK Python

  安装pip
  
# python get-pip.py
Collecting pip
Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 597kB/s
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/66/e8/570bb5ca88a8bcd2a1db9c6246bb66615750663ffaaeada95b04ffe74e12/setuptools-40.2.0-py2.py3-none-any.whl (568kB)
    100% |████████████████████████████████| 573kB 5.1MB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)
    100% |████████████████████████████████| 51kB 8.4MB/s
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-18.0 setuptools-40.2.0 wheel-0.31.1  安装virtualenv
  
# pip install virtualenv
Collecting virtualenv
Downloading https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
    100% |████████████████████████████████| 1.9MB 4.8MB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-16.0.0  创建测试的虚拟python环境
  # virtualenv testenv
  New python executable in /usr/local/python-2.7.15/virtualenv/testenv/bin/python
  Installing setuptools, pip, wheel...done.
  加载虚拟python环境
  # source testenv/bin/activate
  (testenv) # python -V
  Python 2.7.5
  退出虚拟python环境
  (testenv) # deactivate
  使用Python SDK虚拟环境调动AWS命令
  # virtualenv dhchen_env
  New python executable in /data/01/local/rmp/dhchen_env/bin/python2
  Also creating executable in /data/01/local/rmp/dhchen_env/bin/python
  Installing setuptools, pip, wheel...done.
  安装boto3软件
  (dhchen_env) # pip install boto3
  .......
  Installing collected packages: urllib3, jmespath, six, python-dateutil, docutils, botocore, futures, s3transfer, boto3
  Successfully installed boto3-1.9.4 botocore-1.12.4 docutils-0.14 futures-3.2.0 jmespath-0.9.3 python-dateutil-2.7.3 s3transfer-0.1.13 six-1.11.0 urllib3-1.23
  配置AWS key
  (dhchen_env) # aws configure
  AWS Access Key ID : xxx
  AWS Secret Access Key : xxx
  Default region name :
  Default output format :
  (dhchen_env) # cat ~/.aws/credentials
  
  aws_access_key_id = xxx
  aws_secret_access_key = xxx
  (dhchen_env) # cat ~/.aws/config
  
  region = us-west-2
  测试AWS S3调用
  (dhchen_env) # python
  >>> import boto3
  >>> s3 = boto3.client('s3')
  >>> response = s3.list_buckets()
  >>> buckets = for bucket in response['Buckets']]
  >>> print("Bucket List: %s" % buckets)
  参考链接
  https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html



页: [1]
查看完整版本: AWS SDK Python