Using AliCloud API to interact with your OSS
Created#More Posted time:Dec 29, 2015 17:02 PM
1. AliCloud API overview
AliCloud API is a powerful abstraction of interacting the entire cloud infrastructure in a programmable fashion. 90% of the tasks that we can perform through the web console can also be achieved through API calls. This allows system administrators and developers to raise their productivity and embed automation in their day-to-day operation activities.
In order to connect to AliCloud API endpoints, we first need to obtain a pair of Access Key Secret, which is described next below.
2. Access Key Pair Generation
a. Login to the Web Console GUI:
- Click on the Console link on the top panel from the main website (www.alicloud.com)
- Login with your account username and password:
b. Once you are in the Web Console GUI, click on the ‘AccessKeys’ from the top panel
c. On the newly launched page, click “Create AccessKey” on the top right corner
d. Follow the prompted steps, including a step where you may have to click a link in the pop-out window to send a SMS to your registered mobile number with the confirmation 6-digit code.
e. After creation, we should see the key pair as below, with the Access Key Secret hidden
f. Click “Show” to obtain the key secret
g. Make a copy of the Access Key ID and Access Key Secret. We will need them in the next steps of setting up the environment. Please don’t share with anyone else as this would allow API calls across your cloud infrastructure (as we will see later).
3. Python SDK
AliCloud has integrated with various popular SDK: Java, Python, PHP, while many are being actively developed.
For this tutorial, we will use the Python SDK, and we are going to install the SDK for AliCloud OSS
a. Prerequisite: Python 2.7+
b. Install ‘pip’ for managing Python package dependencies management.
c. Use ‘pip’ to install the following AliCloud core packages:
>> pip install aliyun-python-sdk-core >> pip install aliyun-python-sdk-ossPlease note that the above environment can be configured on ANY machines , it doesn’t have to be on any ECS instance running on the AliCloud.
Aliyuncli is built on top of the above core Python AliCloud packages, which provides a simple command line interface to interact with AliCloud infrastructure resources. Instead of writing your own programs from scratch, aliyuncli delivers a ready-to-use toolkit that wraps around most of the essential functions.
a. Use pip to install package ‘aliyuncli’
>> pip install aliyunclib. Configure ‘aliyuncli’ with the pair of Access Key obtained above by running the command, to setup the authentication parameters
>> aliyuncli oss Config --host oss.aliyuncs.com --accessid ***********Em --accesskey ***********0Dr
a. Display all the possible commands under OSS
>> aliyuncli oss
b. Display all existing OSS packages
>> aliyuncli oss GetAllBucket
Happy Learning !!!
~ Ken ^_^