How to create backend using AWS in 3 easy steps (For android developers)

So you are an android developer and have published many applications on google playstore. Creating app for you is no-brainer and delivering app is part of your daily activities. Now you come with some awesome idea and think it is next Instagram or Whatsapp, you have already started designing the workflow of the app in your mind and are charged up to start working on it. But here comes the real difficult part for creating that next Instagram - Creating a backend (which you have no knowledge of) and scaling it to support large number of users (which you hope for).

Now you have option to hire some backend developer (or ask a friend) to get it done but the problem with this approach is that you don’t have enough money to hire backend developer and also there won’t be real fun in it as it won’t fall under DIY (Do It Yourself) approach, which you rigorously follow. Hence you badly need something using which, you can quickly (and with less coding) create a backend and also make it scalable to large audience. Luckily, we have a solution for it, which is called as AWS by Amazon

AWS stands for Amazon Web Services and it offers reliable, scalable, and inexpensive cloud computing services. Using AWS, you can create tables to store data, write code that which will fetch data from database or execute some code at backend (like comparing user credentials), store user profile pictures and everything that your app needs and still can do that all for free for a year, provided you fall into their Free Tier Plan. Following are services offered by AWS:

  1. S3 (For storing profile pictures and other files)
  2. DynamoDB (For storing data)
  3. Lambda (For fetching / writing data to Dynamo DB)

There are many other services provided by AWS but for now we will concentrate on above bare minimum services which are generally required for any given app. To know more about all services visit AWS Products

  1. Setup S3:

As per Amazon:

S3 has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.

What it means for your app is that if you need to store profile pictures of users than it can be stored on S3. Think of S3 as Hard-drive but this Hard-drive is not present on your computer rather than on some virtual machine which is accessible across any device that is connected to internet. To upload / download images (or any file) from S3, AWS provides you Android SDK that can be integrated with your android project. Also as it is scalable, you don’t have to worry about how many users at a given time are uploading / downloading their profile pics, all this traffic handling will be taken care by AWS. To know more about how it can be done using android, visit Store and Retrieve Files with Amazon S3

2. Configure DynamoDB:

DynamoDB is NoSQL database provided by AWS which can be used to store data required by your app. NoSQL is new form of database which stores data in form of key-value pair. If you are new to NoSQL than I suggest to have a look into this article. AWS also provides UI console to view tables and data inside the tables (just like phpMyAdmin for MySQL). One more advantage of using DynamoDB is that you don’t have to worry anymore about scalability of database as you can scale up or scale down your tables’ throughput capacity without downtime or performance degradation, and use the AWS Management Console to monitor resource utilization and performance metrics.

To start with basics of AWS DynamoDB, visit DynamoDB introduction and to straight away start with creating tables, visit Creating Tables and Loading Sample Data. Amazon has also provided step by step guide of integrating DynamoDB with android app which can be found here

3. Deploy code to AWS Lambda:

This is the most exciting service of AWS. Often times, there is a requirement that some processing should be done on server side instead of client side, for example if user is trying to login to your app, in that case username and password should be fetched from database and should be verified with credentials provided by the user in your app. For this type of requirement, you will need to install some server (like apache / tomcat) and write code that fetches data from database and provide the result to the app by exposing some api. This entire process is troublesome as you need to maintain your server which you don’t have much knowledge of at first place.

This is where AWS Lambda comes into picture. Using eclipse and AWS Java Sdk, you can write code to fetch data from DynamoDB in Java and can deploy this code on AWS Lambda, there is no need to install any server or worry about its scalability since it can be easily done using AWS Lambda management console. To read more about AWS Lambda, visit What Is AWS Lambda.

You can deploy jar to Lambda or can directly upload code from eclipse to Lambda and trigger this Lambda using AWS android Sdk from your app whenever user presses login button and AWS Lambda will fetch credentials from DynamoDB and send result after comparing user provided credentials. Since you are an android developer, writing above code in Java won’t be a big deal for you and can be easily done by following Programming Model for Authoring Lambda Functions in Java and AWS Lambda Update — Run Java Code in Response to Events.

So there it is, Create highly scalable backend with the help of AWS and just with the knowledge of Java and that too using their Free Tier plan. I wish you Best of Luck for your next big app!