Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

AWS SDK Python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Install pip

[root@xxxxxx ~] # python get-pip.pyCollecting pip Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB) 100% | ██ | 1.3MB 597kB/sCollecting setuptools Downloading https://files.pythonhosted.org/packages/66/e8/570bb5ca88a8bcd2a1db9c6246bb66615750663ffaaeada95b04ffe74e12/setuptools-40 .2.0-py2.py3-none-any.whl (568kB) 100% | ██ | 573kB 5.1MB/sCollecting wheel Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB) 100% | █ █ | 51kB 8.4MB/sInstalling collected packages: pip Setuptools, wheelSuccessfully installed pip-18.0 setuptools-40.2.0 wheel-0.31.1

Install virtualenv

[root@xxxxxx ~] # pip install virtualenvCollecting 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/sInstalling collected packages: virtualenvSuccessfully installed virtualenv-16.0.0

Create a virtual python environment for testing

[root@xxxxxx virtualenv] # virtualenv testenv

New python executable in/ usr/local/python-2.7.15/virtualenv/testenv/bin/python

Installing setuptools, pip, wheel...done.

Load virtual python environment

[root@xxxxxx virtualenv] # source testenv/bin/activate

(testenv) [root@xxxxxx virtualenv] # python-V

Python 2.7.5

Exit the virtual python environment

(testenv) [root@xxxxxx virtualenv] # deactivate

Use the Python SDK virtual environment to mobilize the AWS command

[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.

Install boto3 softwar

(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

Configure 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

Test AWS S3 call

(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)

Reference link

Https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report