从ios应用程序连接到Amazon EC2实例 [英] Connect to an Amazon EC2 instance from an ios application

查看:143
本文介绍了从ios应用程序连接到Amazon EC2实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个使用Amazon Web Services作为后端的ios应用程序。我在RDS中有一个MySQL数据库,想从应用程序查询该数据库以检索该应用程序的内容。经过一些研究,看来我应该通过添加自己的API来查询数据库到EC2实例的方法。然后,我不是从应用程序直接访问RDS实例,而是访问EC2实例上的API,该API为我访问了RDS实例。首先,这是走的路吗?我也愿意接受其他建议。



这是我到目前为止所做的,在阅读帖子:


  1. 在我的EC2实例上安装了apache和php。

  2. 为我的EC2实例获取了一个弹性IP地址。

  3. 添加了一个文件(我们称其为检索-data.php)使用我的RDS实例端点,用户名和密码查询数据库并返回数据。

从我的ios应用程序中,然后我可以向 elastic_ip_address_of_my_ec2_instance / retrieve-data.php 发送一个http请求,以从我的应用程序中的RDS数据库中获取数据。这是要走的路吗?可以通过任何方式对此进行改进吗?

解决方案

对于可能会觉得有用的任何人,以下是对您的步骤的总结

设置:



以下步骤涵盖三个选项:



A =没有域名,没有负载平衡



B =是域名,没有负载平衡



C =是域名,是负载平衡


  1. (A + B + C)创建一个EC2实例。

  2. (A + B + C)在您的实例上安装所有必需品。至少,您将需要apache2以及希望用于实例上运行的任何后端脚本的语言。我用过php。

  3. (A + B)如果您不想让域名用于访问您的EC2实例,或者您想要域名但不要不需要负载平衡,您将需要为实例获取一个弹性IP地址。这可以通过AWS轻松完成。 (C)如果您要使用域名和负载平衡,则不需要弹性IP地址。继续获取域名。我用的是namecheap.com。他们目前(2015年8月)拥有.xyz TLD,每年的价格仅为1.18美元。

  4. (A + B + C)将后端文件添加到您在EC2上安装的apache网络服务器中实例在步骤2中。

  5. (B + C)在Amazon Route 53中设置托管区域。注意:Route 53不包含在AWS免费套餐中,因此不是免费的。费用在此处。 (仅B)将A记录添加到Route 53托管区域中,该记录指向您的EC2实例的弹性IP。

  6. (B + C)传输域的名称服务器名称到3-5个名称服务器的路径,这是第53步在完成第5步后给您的。转移将从您注册域名的站点完成。

  7. (C)设置负载平衡适用于AWS中的EC2实例。请注意您的负载均衡器的端点。

  8. (C)将别名记录添加到Route 53托管区域,该记录指向负载均衡器的端点。

在EC2上访问文件



假设您有一个php脚本myscript在步骤4中保存到服务器的.php。要在设置完成后在EC2服务器上运行此脚本,您可以执行以下操作:



A-打开Web浏览器,然后在地址栏中输入以下内容:elastic_IP_of_your_EC2_instance / myscript.php



B + C-打开Web浏览器,然后在地址栏中输入以下内容:yourdomain.com/myscript.php



希望这会有所帮助!


I am trying to make an ios application that uses Amazon Web Services as its backend. I have an MySQL database in RDS and want to query this database from the app to retrieve content for the app. After some research, it looks like I should approach this by adding my own API for querying the database to an EC2 instance. Then, rather than directly accessing the RDS instance from the app, I access the API on the EC2 instance which accesses the RDS instance for me. Firstly, is this the way to go? I'm open to other suggestions too.

Here's what I have done so far, after reading this post:

  1. Installed apache and php on my EC2 instance.
  2. Obtained an elastic IP address for my EC2 instance.
  3. Added a file (let's call it retrieve-data.php) to apache that uses my RDS instance endpoint, username, and password to query the database and return data.

From my ios application, I can then send an http request to elastic_ip_address_of_my_ec2_instance/retrieve-data.php to get the data from my RDS database in my app. Is this the way to go? Can this be improved upon in any way?

解决方案

For anyone who might find this useful, below is a summary of the steps you can take to get this all set up.

Set-up:

There are three options covered in the below steps:

A = NO domain name, NO load balancing

B = YES domain name, NO load balancing

C = YES domain name, YES load balancing

  1. (A+B+C) Create an EC2 instance.
  2. (A+B+C) Install all the necessities on your instance. At the very least, you'll want apache2 and whatever language(s) you wish to use for any backend scripts you want to run on your instance. I've used php.
  3. (A+B) If you don't want to get a domain name to use to access your EC2 instance, or if you want a domain name but don't need load balancing, you'll want to get an elastic IP address for your instance. This can be easily done through AWS. (C) If you want to use a domain name and load balancing, you won't need an elastic IP address. Go ahead and get yourself a domain name. I used namecheap.com. They currently (August, 2015) have .xyz TLDs for just $1.18 USD/year.
  4. (A+B+C) Add your backend files to the apache web server you installed on your EC2 instance in step 2.
  5. (B+C) Set up a hosted zone in Amazon Route 53. NOTE: Route 53 is NOT included in the AWS free tier and is therefore NOT FREE. The costs are here. (B only) Add A record(s) to your Route 53 hosted zone that point to the elastic IP of your EC2 instance.
  6. (B+C) Transfer the name servers of your domain name to the 3-5 name servers Route 53 gave you after completing step 5. The transfer will be done from the site you registered your domain name with.
  7. (C) Set up load balancing for your EC2 instance(s) in AWS. Note your load balancer's end point.
  8. (C) Add alias record(s) to your Route 53 hosted zone that point to your load balancer's end point.

Accessing your files on EC2

Let's say you have a php script myscript.php that you saved to your server in step 4. To run this script on your EC2 server after finishing the set up, you can do the following:

A - Open up a web browser and enter the following into the address bar: elastic_IP_of_your_EC2_instance/myscript.php

B+C - Open up a web browser and enter the following into the address bar: yourdomain.com/myscript.php

Hope this is helpful!

这篇关于从ios应用程序连接到Amazon EC2实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆