您好,登錄后才能下訂單哦!
安裝pip
[root@xxxxxx ~]# 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
[root@xxxxxx ~]# 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環境
[root@xxxxxx virtualenv]# virtualenv testenv
New python executable in /usr/local/python-2.7.15/virtualenv/testenv/bin/python
Installing setuptools, pip, wheel...done.
加載虛擬python環境
[root@xxxxxx virtualenv]# source testenv/bin/activate
(testenv) [root@xxxxxx virtualenv]# python -V
Python 2.7.5
退出虛擬python環境
(testenv) [root@xxxxxx virtualenv]# deactivate
使用Python SDK虛擬環境調動AWS命令
[root@ec2t-dbaadmin-01 rmp]# 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) [root@ec2t-dbaadmin-01 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) [root@ec2t-dbaadmin-01 dhchen_env]# aws configure
AWS Access Key ID [None]: xxx
AWS Secret Access Key [None]: xxx
Default region name [us-west-2]:
Default output format [None]:
(dhchen_env) [root@ec2t-dbaadmin-01 .aws]# cat ~/.aws/credentials
[default]
aws_access_key_id = xxx
aws_secret_access_key = xxx
(dhchen_env) [root@ec2t-dbaadmin-01 .aws]# cat ~/.aws/config
[default]
region = us-west-2
測試AWS S3調用
(dhchen_env) [root@ec2t-dbaadmin-01 .aws]# python
>>> import boto3
>>> s3 = boto3.client('s3')
>>> response = s3.list_buckets()
>>> buckets = [bucket['Name'] for bucket in response['Buckets']]
>>> print("Bucket List: %s" % buckets)
參考鏈接
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。