开发者社区 问答 正文

Using AliCloud API to interact with your OSS

[Reprint from ken's post]



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-oss


Please 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.
  
4.   Aliyuncli
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 aliyuncli
b. 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



展开
收起
winson.zhang 2016-03-02 11:49:41 7275 分享 版权
阿里云 AI 助理回答

Ken's post provides a comprehensive guide to getting started with Alibaba Cloud API usage, focusing on accessing the API, generating access key pairs, setting up the Python SDK for interacting with AliCloud Object Storage Service (OSS), and using the aliyuncli command-line tool. Here's a summary and some additional context:

1. AliCloud API Overview

The AliCloud API enables users to programmatically manage their cloud resources, replicating most tasks available in the web console. This is crucial for automation, enhancing productivity, and integrating cloud services into your applications or IT operations.

2. Access Key Pair Generation

  • Login: Visit the Alibaba Cloud website and log in to the management console.
  • AccessKey Management: Navigate to the 'AccessKeys' section under security settings.
  • Create AccessKey: Click "Create AccessKey" to generate a new pair of keys – an Access Key ID and a Secret Access Key. The secret key will be shown only once, so it's important to save it securely as it grants programmatic access to your account resources.

3. Python SDK Setup

  • Prerequisites: Ensure Python 2.7 is installed (though it's recommended to use Python 3.x due to Python 2's end-of-life).
  • Install pip: If not already installed, get pip to manage Python packages.
  • Install AliCloud SDKs: Use pip to install the core SDK and the specific one for OSS (aliyun-python-sdk-core and aliyun-python-sdk-oss). Note that these installations can be done on any machine with Python, not necessarily an ECS instance within Alibaba Cloud.

4. AliyunCLI

  • Installation: Install the aliyuncli package via pip, which offers a CLI interface for managing AliCloud resources.
  • Configuration: After installation, configure aliyuncli with your Access Key ID and Secret obtained earlier. The example command sets up the CLI to interact with OSS services.

Additional Tips: - Security Best Practices: Keep your Access Key Secret secure and rotate keys periodically for security reasons. - Python Version: It's advisable to use Python 3 instead of Python 2.7 since Python 2 reached its end-of-life and no longer receives updates or support. - SDK Updates: Always check for the latest versions of the SDKs and tools before installing, as technology evolves rapidly. - CLI Usage: aliyuncli simplifies many tasks but explore its documentation for the full range of commands and options available for different services.

By following Ken's steps, you'll have set up the foundation for programmatically managing your Alibaba Cloud infrastructure using Python SDK or the command line, enabling efficient automation and control over your resources.

有帮助
无帮助
AI 助理回答生成答案可能存在不准确,仅供参考
0 条回答
写回答
取消 提交回答