Connect to an Amazon EC2 instance from an ios application - ios

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:
Installed apache and php on my EC2 instance.
Obtained an elastic IP address for my EC2 instance.
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?

Edit: changing this answer to whats in my comment below;
The solution is what is suggested in How to connect amazon RDS in iOS, which is installing a webserver on the EC2 instance and writing a web app to make your RDS calls for you. This will involve some kind of web programming, there's a simple explanation here in the top comment. Then you can use RestKit to implement the calls from your app to the EC2 instance: github.com/RestKit/RestKit

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
(A+B+C) Create an EC2 instance.
(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.
(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.
(A+B+C) Add your backend files to the apache web server you installed on your EC2 instance in step 2.
(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.
(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.
(C) Set up load balancing for your EC2 instance(s) in AWS. Note your load balancer's end point.
(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!

Related

API gateway to my elastic beanstalk docker deployed app

My backend is a simple dockerized Node.js express app deployed onto elastic beanstalk. It is exposed on port 80. It would be located somewhere like
mybackend.eba-p4e52d.us-east-1.elasticbeanstalk.com
I can call my APIs on the backend
mybackend.eba-p4e52d.us-east-1.elasticbeanstalk.com/hello
mybackend.eba-p4e52d.us-east-1.elasticbeanstalk.com/postSomeDataToMe
and they work! Yay.
The URL is not very user friendly so I was hoping to set up API gateway to allow to me simply forward API requests from
api.myapp.com/apiFamily/ to mybackend.eba-p4e52d.us-east-1.elasticbeanstalk.com
so I can call api.myapp.com/apiFamily/hello or api.myapp.com/apiFamily/postMeSomeData
Unfortunately, I can't figure out (i) if I can do this (ii) how to actually do it.
Can anybody point me to a resource that explains clearly how to do this?
Thanks
Yes, you can do this. For this to happen you need two things:
a custom domain that you own and control, e.g. myapp.com.
a valid, public SSL certificate issued for that domain.
If you don't have them, and want to stay within AWS ecosystem, you can use Route53 to buy and manage your custom domain. For SSL you can use AWS ACM which will provide you with free SSL certificate for the domain.
AWS instructions on how to set it up all is:
Setting up custom domain names for REST APIs

Getting started with AWS backend for iOS

I've been coding on iOS for awhile. I'm getting started to use AWS as a cloud backend to store my user's data for my iOS app as well as a server that can handle real time event in multiplayer mode. I understand that there are many services like Amazon Cognito that allows user login via public providers, Dynamo DB that provides noSQL storage, EC2 that help me create server instances. However, I'm really confuse on how I can actually get started.
Here's some stuff that I really need help on:
I don't really want to use public providers like facebook for my users to sign in/sign up. I'd really prefer it if there could be relational database that is similar to how I cache data on local sqlite files using core data.
And I also need some help on getting my ID tokens for those services if I choose not to use cognito, or must I?
I would really appreciate it if you guys can give me some clues on how I can get started on these. Thank you so much! :D
Depending on how you expect your app to evolve there are several approaches you can take.
Option 1: Minimal scalability / low cost
All you really need is a single free EC2 micro instance. On the instance you can build a full LAMP stack in seconds. Once you have built it you can start writing an application to handle your app in your preferred language. Ruby is a la mode but any language will work. Your database will be stored on the actual instance. If you go with this route, one thing you should do is use an elastic IP address so that if your server ever goes down you can point the elastic IP to another instance. You should also periodically backup your server.
Option 2: Maximum scalability / variable cost
Use RDS to store your database. This will mean that any EC2 instance will be able to reach your data so you can have an unlimited number of servers. Then build an EC2 instance just like in option 1 but point your application to the RDS instance. Use a load balancer in front of your EC2 instance to scale up in response to changes in utilisation. And the elastic IP address should point to the load balancer.
Building a LAMP stack on EC2
Open the EC2 console
Select launch instance
Pick the Linux AMI offered by Amazon and a micro instance
Create a .pem key (keep is safe on your system or you will not be able to access your instance)
Select the default security group
Open your terminal window and type: ssh -i path_to_pem ec2-user#your_instance_public_address
In the EC2 instance type sudo yum update
Then type sudo yum install httpd24 php55 php55-mysqlnd mysql55
sudo apachectl start
You now can navigate to the public address of your instance in safari and assuming I did not forget any steps you should see the apache welcome page.

How to publish and host a MVC4 application in your domain?

I have a webdomain www.MyDomain.com and a MVC4 web application MyMVCWebApp.
First I publish the application to a local destination.
For instance: C:\TempLocation
And then I host it to my domain with a FTP-tool (FileZilla??)
The files will be hosted but I can't find the webpage.
Which url do I have to write?
http://www.MyDomain.com/MyMVCWebApp/Home/Index.chtml or something?!
Do I have change the settings in my web.config?
What do I have to do?
You can't host an application on a domain.
An application is hosted on a web server. A domain name is only a way to translate an easy to remember address like "www.google.com" to the web server ip address which looks like 173.194.66.104
It is possible to purchase a domain without a web server.
So before going further:
Check if you actually bought a domain only, or a domain with a server
Your domain should redirect to your server ip address, you can see if he is correctly configured by opening a command prompt and doing
C:\> ping www.yourdomain.com
If this is not the case you will need to update the A record of your domain, and wait for the update to be replicated on DNS server worldwird.
If you have a managed server, you should check your hosting provider website. They usually provide in depth documentation, and they all have a different way to do things. Most of the time indeed you will be able to upload your files using a FTP software such as Filezilla.
However, in order to host a MVC 4 application you need a server with
the IIS web server, which means that you need a Windows server. So if
you have a Linux server, you should contact your hosting provider
support and tell them you made a mistake during your order. (It is
possible to host a MVC 4 application on Linux, but I don't think it
is often provided on managed servers)
If you have a dedicated server you are on your own.
The URL you will have to write to access your application will depends on what you have configured in the RegisterRoutes method of the RouteConfigs.cs file.
I recommend you to watch the last video on this page to have a better overview of the possibilities.

Rails Rubber EC2 Amazon AWS Railscast

Hi I have successfully deployed my app to amazon aws using this railscast
http://railscasts.com/episodes/347-rubber-and-amazon-ec2
my app shows up here on this url http://web01.foo.com/
on my local machine only.
I am slightly confused, if I deployed it why can't other people see it. How do you make it live for all to see?
if anyone is familiar with this rails cast please enlighten me, I am still trying to learn about the architectures of amazon aws hosting.
Thank You
Judy
Rubber automatically sets up your /etc/hosts file for you. In order to make it publicly viewable you need to have the DNS servers point to that address in your /etc/hosts file.
So basically, go to your DNS host provider, and add an entry that points the domain name you own to the ip address of web01.foo.com and it should load okay.
In your amazon EC2 dashboard click on the instance. You will get the public domian of your server. Use PUBLIC domain not private one

Using a VPN to get a static IP on Heroku

I need to connect to an API with my Heroku/Rails app where I need to have a static IP.
I know about the add-on proximo - https://devcenter.heroku.com/articles/proximo - but it is insanely priced, so that's out of the question.
Most people in my situation ends up deploying to EC2 instead and using a an Elastic IP as their static IP. I've also tried this and it works, but I find the whole flow of playing around with EC2 really cumbersome.
I've read in some answers that it is possible to set up an EC2 server and use it as a proxy for your Heroku/Rails app - Heroku Static IP for SFTP - but it sounds very cryptic for a person who is not very server-savvy.
Can someone give a step-to-step tutorial on how to set up your Heroku/Rails app to use your EC2 instance as a proxy?
In short: I would just switch to AWS. There is a little bit of a learning curve but it's not too difficult. Here is a presentation I gave on it geared toward front-end devs:
https://speakerdeck.com/krunkosaurus/intro-to-scaling-your-web-app-on-the-cloud-with-aws-for-frontend-developers-part-1
Amazon has 9 regions each with 3-5 "Availability Zones". I know that Heroku uses AWS but am not sure if you get to decide (or know) which AWS region and AZ your actual server is hosted.
Whatever it is, you should host your proxy server in the same Region (better yet, even the same Availability Zone). Setting up an EC2 there is easy just use the web console and be sure to give it an Elastic IP so the adress doesn't ever change. Then point your DNS away from your Heroku instance (dyno?) to this EC2 instance. From there you can either install Nginx or HAProxy.
I've just setup QuotaGuard Static as a more robust, better value static IP service that can be used by Heroku apps.
It's hosted on EC2 so you get the low latency benefits without having to start managing servers.
Hello you can use this answer to see how to use NGINX as a reverse proxy.
https://stackoverflow.com/a/27874505/1345865
http://blog.talenox.com/post/107675614745/how-to-setup-static-ip-on-heroku
Fixie is very affordable option for getting static IP address on Heroku. The documentation section has a lot of examples for different languages and frameworks, including Ruby.

Resources