Connecting Android Application to MySQL Database hosted on AWS - android

Good day everyone,
I have developed an android application and I would like to store my business information on MySQL database. I have decided to use amazon services for this project however I'm very confused how to allow my application to establish a proper/secure connection with MySQL database in order to pull and push the information into it. I have read many articles/stack overflow posts and realized I have to deploy a REST api in order to provide a layer between the application and the actual database. However with AWS being very confusing, in my opinion, i'm super lost.
Could any of you gentle folks provided with the step-by-step guide what services to use, how to connect them together and deploy them in order to be able to use it in my android application. Or maybe an article describing the steps? I don't really need a detailed explanation just a nudge in the right direction and I will try to figure out the rest.
Thank you greatly.

First of all, connecting to MySQL directly from an Android application is not secure, since you need the MySQL database access credentials for the app to communicate with the database.
This is why people recommend using a REST API Layer in between the MySQL database which you can implement using API Gateway and Lambda. This can be secured using a strong authentication mechanism for the API and using SSL for encrypting the messages at Transit.
However, this is not the case if you plan to connect to AWS DynamoDB from Android App. You can enforce Fine-Grained Access Permission to DynamoDB tables and roles using IAM policies.
Few Tutorials that might help,
Serverless REST API in Minutes with Serverless Framework.
Querying RDS MySQL with NodeJS Lambda Function.
Using Mobile Hub (To Simplify Things).
User Authentication with Cognito UserPools.

Related

How to access PostgreSQL database data from an Android App?

I am making an app which requires a database, so I want to use PostgreSQL from Google Cloud Platform, I did not find any tutorials helping me to do that, How to access the data? a link at Can i use PostgreSQL or mySQL in android App development
no longer works or outdated, found the REST API documentation for Cloud SQL but unable to understand if these APIs are just to access DATABASE or the data inside DATABASE?
As mentioned in the accepted answer to the post suggested by #JGH, there are a few ways to access data of a DB from an Android App.
The most commonly used way is definitely by communicating to a service hosted on a server that can connect to the DB, and provides endpoints to request any operation (read, write, update, delete).
However, since you specified a direct connection from the Android App to the Cloud SQL instance, the best option would be to try to make it work with the JDBC connecting to, possibly, a public IP of the Cloud SQL instance. You may find more information in the Connecting to Cloud SQL from external applications documentation.

Connecting Android to AWS RDS [duplicate]

Background
I have a EC2 instance with a RDS instance(MYSQL) associated with it.
I want to use a android app to execute queries on that MYSQL instance.The Android sdk of amazon does not support RDS.
Problem
How do I connect my android app with RDS instance?Is it possible to use RDS(MYSQL) with an android application without sdk support?
RDS is not a database engine. It's a service that manages the infrastructure for you that's required to maintain a highly available and fault tolerant database. It supports a number of different engines such as MySQL as you mentioned. Please read the docs for more information.
You need to connect to your RDS MySQL instance the same way you would connect to any MySQL database. Using a library that supports MySQL, and using the hostname, username and password for your database.
However, it's probably not the best design to have phone clients connecting to your database remotely. The best thing to do would be to put a REST API on AWS that interfaces with your database.
Having n users connected to your database from each handset using your app is probably a bad idea. It means you need to have more power in your database, greatly hinders your scalability and makes things less secure as the database is exposed to the internet. With an API in front of it, you can build a much more fault tolerant, scalable and solution.
The "cloud way" to build mobile apps is to (within reason) build your application logic on the cloud and simply have your client code connect to your API. This way you can spread to more platforms (eg. IOS, Web) much more easily as you won't have to manage separate application level code for each platform. You'll just need to manage code that integrates with your already existing API.
Take a look at this whitepaper. Ignore the web server tier and focus on the App Server and Database tiers. This is probably the best design to go by.

Using Amazon RDS with android application

Background
I have a EC2 instance with a RDS instance(MYSQL) associated with it.
I want to use a android app to execute queries on that MYSQL instance.The Android sdk of amazon does not support RDS.
Problem
How do I connect my android app with RDS instance?Is it possible to use RDS(MYSQL) with an android application without sdk support?
RDS is not a database engine. It's a service that manages the infrastructure for you that's required to maintain a highly available and fault tolerant database. It supports a number of different engines such as MySQL as you mentioned. Please read the docs for more information.
You need to connect to your RDS MySQL instance the same way you would connect to any MySQL database. Using a library that supports MySQL, and using the hostname, username and password for your database.
However, it's probably not the best design to have phone clients connecting to your database remotely. The best thing to do would be to put a REST API on AWS that interfaces with your database.
Having n users connected to your database from each handset using your app is probably a bad idea. It means you need to have more power in your database, greatly hinders your scalability and makes things less secure as the database is exposed to the internet. With an API in front of it, you can build a much more fault tolerant, scalable and solution.
The "cloud way" to build mobile apps is to (within reason) build your application logic on the cloud and simply have your client code connect to your API. This way you can spread to more platforms (eg. IOS, Web) much more easily as you won't have to manage separate application level code for each platform. You'll just need to manage code that integrates with your already existing API.
Take a look at this whitepaper. Ignore the web server tier and focus on the App Server and Database tiers. This is probably the best design to go by.

mobile apps: restful api or sdk dynamodb

I'm building my first app which uses an external database for storing data..
And I'm struggling with the following question:
How to connect with my database: use the Amazon DynamoDB sdk for Android or create a restful api based on NodeJS on my own server, which passes the data to DynamoDB?
I'm very new to this and when I look over the internet I see amazon suggesting to use the SDK.
The only problem is, if I want to change the data structure in the feature, what kind of problems will my users experience with the current versions of the app? And is it safe to save my Amazon keys inside the app (cause people may be able to decompile the app)?
On the other hand, I do have to pay for the extra server which handles the connections between my app and DynamoDB. So... is it worth it?
So I'm quite struggling with this.... What do you guys think?
I would go for direct access from your mobile application to DynamoDB.
This would allow you to scale your application much easier : you do not need to maintain, operate, secure a middle layer, AWS does that for you. You will also save on the cost of running your couple of NodeJS servers, load balancers etc ...
You should not store access keys / secret keys in your application but rather use AWS Cognito Identity service to dynamically receive access keys and secret keys for your user session. These keys will be limited in scope to whatever permission you define for your Cognito users and limited in time (default is 15 min)
Cognito works with backend identity providers to authenticate your users (Facebook, Google, Amazon, openID connect or your own backend) and can also work with unauthenticated users.
More about Cognito : http://aws.amazon.com/cognito/
More about Cognito ID for Android Mobile Applications :http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/cognito-auth.html
I'm not sure that the accepted answer is complete because it does not acknowledge use cases, and it does not address the question asked of "what if I want to change the data structure." Well, if you have outdated clients, and change the data structure of the documents in your nosql database, then those clients will not be able to access it. I don't believe DynamoDB offers a middleware platform to support this kind of old-to-new model adaptation. You'll have to force an update to your clients.
In fact, there are many operations beyond user-based permissions (which Cognito does do well) like this that you might need middleware for. Perhaps you want sorting logic to occur at request-time, and not maintain a copy of that sorting logic in every client application.
The question of "is it worth it" probably depends on the complexity of your application and your users' relationship with the data (ie. if the presentation layer basically just wrapped data -- then directly access DynamoDB. If you your presentation layer is not just wrapped data, then you should probably use custom middleware). In truth, I stumbled upon this question while running my own cost-benefit analysis, and am not sure which approach I will take. Another major factor of mine is that I might choose to switch database solutions in the future.. this will be more challenging to update on every client, if my clients are directly accessing the DB.
The one certain conclusion I've reached is that you should use middleware somewhere in your system, such that you can decouple your database vendor from either the client logic or the server logic as much as possible, eg. in a mobile app:
writeToDatabase(Data data){writeToDynamo(data);}
To achieve this, AWS suggests using Amazon Api Gateway as a proxy for AWS services, and even has premade configurations for Amazon API Gateway to behave as AWS service proxy.

Connecting Android app to amazon RDS

I have an Android application and I want to move my local database in the cloud. I decided for a SQL database and not for a NoSQL, because I want to execute complex queries. I created a database instance in RDS from Amazon and I populated the database.
Now I want to connect my mobile app to my cloud database. I saw samples for NoSQL database connection, but I wasn't able to find examples for RDS. I saw that it is recommended to create a web service and connect to that web service, but it seems much more complicated than using a NoSQL and this doesn't feel right.
Does Amazon offer some API/service for Android - RDS connection? Do you know any sample code that handles this aspect?
Does Amazon offer some API/service for Android - RDS connection?
No. AWS does not currently have an API for interacting with an RDS instance.
Do you know any sample code that handles this aspect?
You may want to access your database with PHP and get a JSON response. If your RDS instance is using MySQL then you’re in luck. There is already a lot of documentation on connecting Android to MySQL using PHP. You can get great sample code and instructions on this blog post.
Here is a very popular reference for connecting Android and MySQL.

Categories

Resources