AWSSDKPython-创新互联
安装pip
创新互联建站长期为千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为海州企业提供专业的成都网站制作、网站设计、外贸网站建设,海州网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。[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
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文标题:AWSSDKPython-创新互联
本文路径:http://pwwzsj.com/article/dcdjds.html