Amazonrds 简明教程
Amazon RDS - Interfaces
RDS 接口是访问我们创建的 RDS 服务的一种方法。创建和配置 RDS 服务后,我们需要访问数据,将数据上传到此数据库并运行一些其他程序,这些程序应该能够连接到数据库。数据库的最终用户访问和操作数据需要这些接口,而不一定是创建数据库的 AWS 账户持有人。
The RDS interfaces are a way to access the RDS service we create. After the creation and configuration of the RDS service there is a need of accessing the data, uploading data to this database and running some other program which should be able to connect to the database. Such requirements of accessing and manipulating data by end users of the database and not necessarily the AWS account holder which created the database needs these interfaces.
有三种主要接口。
There are three main such interfaces.
GUI Console
这是最简单的接口,用户可以通过 Web 浏览器登录并开始使用 DB 服务。此类访问的缺点是,需要人员与 RDS 服务进行交互,而且我们无法运行数据库程序来执行一些常规任务,如备份或分析数据库等。
This is the simplest of the interfaces where the user can login through a web browser and start using the DB services. The down side of such access is , it needs a human to interact with the RDS services and we cannot run a database program to do some regular tasks like – backup or analysing the DB etc.
Command Line Interface
它也被称为 CLI 访问,您可以在其中通过应安装在您使用的客户端计算机中的 AWS 命令提示屏幕执行 DB 命令。以下是使用您将访问 AWS 服务的 CLI 在您的本地系统中进行安装的步骤。
It is also called CLI access where you can execute DB command through the AWS command prompt screen which should have been installed in the client computer you are using. Below are the steps to install CLI in your local system using which you will access AWS services.
安装 AWS CLI 的步骤如下。
The steps to install AWS CLI are as below.
Step-1
检查您环境中的 python 版本。
Check for the version of python in your environment.
ubuntu@ubuntu:~$ python -V
ubuntu@ubuntu:~$ python3 -V
当我们运行以上程序时,我们得到以下输出:
When we run the above program, we get the following output −
Python 2.7.12
Python 3.5.2
如果版本低于 2.6 或 3.3,则需要升级您的系统中的 python 版本。
If the version is less than 2.6 or 3.3 , then you need to upgrade the version of python in your system.
Step -2
检查名为 pip 的 python 软件包的可用性。它将需要安装 AWS CLI。
Check for availability of the python package named pip . It will be needed to install AWS CLI.
Pip -V
当我们运行以上程序时,我们得到以下输出:
When we run the above program, we get the following output −
pip 10.0.1 from /home/ubuntu/.local/lib/python3.5/site-packages/pip (python 3.5)
Step -3
发布以下命令以安装 AWS CLI。
Issue the following command to install the AWS CLI.
pip install awscli –upgrade –user
aws --version
当我们运行以上程序时,我们得到以下输出:
When we run the above program, we get the following output −
Aws-cli/1.11.84 Python/3.6.2 Linux/4.4.0
Step-4
接下来,我们用凭据配置 aws CLI。我们发布此命令,然后逐个输入所需值。
Next we configure the aws CLI with credentials. We issue this command and then input the required values one by one.
aws configure
当我们运行以上程序时,我们得到以下输出:
When we run the above program, we get the following output −
AWS Access Key ID [None]: ****PLE
AWS Secret Access Key [None]: ********8
Default region name [None]: us-west-2
Default output format [None]: json
准备好上述配置后,您现在即可通过 CLI 与 AWS 环境进行通信,以设置和使用 Amazon RDS。在之后的章节中,我们将了解如何进行操作。
With the above configuration in place you are now ready to use CLI for communicating with AWS environments for setting up and using amazon RDS. In the next chapters we will see how we can do that.
AWS API
Amazon Relational Database Service (Amazon RDS) 也提供应用程序编程接口 (API)。当系统之间交换信息,而不是由人发出命令及接收结果时,会用到 API。例如,如果您希望当交易数量达到某个阈值时,自动将数据库实例添加到 RDS 服务,则可以使用 AWS SDK 编写程序,该程序会监视数据库交易数量,并达成了所需条件后,立即创建 RDS 实例。
Amazon Relational Database Service (Amazon RDS) also provides an application programming interface (API). APIs are used when the information is exchanged between the systems rather than a human issuing the commands and receiving the result. For example, if you want to automate the addition of database instances to a RDS service when the number of transactions reach certain threshold , then you use a AWS SDK to write a program which will monitor the number of database transactions and spin-off a RDS instance when the required condition is met.
以下是一个创建数据库快照副本的 API 代码示例。这是一个 Python 程序,它使用名为 boto3 的 AWS SDK。boto3 中的客户端库有一个名为 copy_db_snapshot 的方法,此 Python 程序会调用该方法,使用所需参数创建数据库快照副本,如下所示。
Below is an example of API code that creates a copy of a DB snapshot. It is a python program which uses AWS sdk named boto3. The client library in boto3 has a method named copy_db_snapshot which is called by the python program to create a copy of the DB snapshot with the required parameters as shown.
import boto3
client = boto3.client('rds')
response = client.copy_db_snapshot(
SourceDBSnapshotIdentifier='mydbsnapshot',
TargetDBSnapshotIdentifier='mydbsnapshot-copy',
)
print(response)
运行上述程序后,我们会得到一个响应,其中描述了复制事件的各种属性。在这里,字符串术语代表由用户为其环境定义的各种参数名称。例如,VpcID 代表了执行复制操作的 VPC 的 ID。
When the above program is run we get the response which describes the various properties of the copy event. Here the term string represents the various names of parameters which is defined by the user for their environment. For example VpcID represents the ID of the vpc in which the copy action is happening.
{
'DBSnapshot': {
'DBSnapshotIdentifier': 'string',
'DBInstanceIdentifier': 'string',
'SnapshotCreateTime': datetime(2015, 1, 1),
'Engine': 'string',
'AllocatedStorage': 123,
'Status': 'string',
'Port': 123,
'AvailabilityZone': 'string',
'VpcId': 'string',
'InstanceCreateTime': datetime(2015, 1, 1),
'MasterUsername': 'string',
'EngineVersion': 'string',
'LicenseModel': 'string',
'SnapshotType': 'string',
'Iops': 123,
'OptionGroupName': 'string',
'PercentProgress': 123,
'SourceRegion': 'string',
'SourceDBSnapshotIdentifier': 'string',
'StorageType': 'string',
'TdeCredentialArn': 'string',
'Encrypted': True|False,
'KmsKeyId': 'string',
'DBSnapshotArn': 'string',
'Timezone': 'string',
'IAMDatabaseAuthenticationEnabled': True|False,
'ProcessorFeatures': [
{
'Name': 'string',
'Value': 'string'
},
]
}
}