In this self-guided workshop you will build an end-to-end serverless tracking application for your mobile devices powered by Amazon Web Services (AWS).
The beauty of serveless computing is, that it allows you to focus entirely on your application rather than managing servers and scaling the environment. It is often also more cost efficient since you avoid overprovisioning and always have just the right capacity. This workshop is build around technologies such as DynamoDB, Lambda, API Gateway, Simple Storage Service (S3), CloudFront, Route 53 and Cognito.
This initial architecture will grow and change if you follow the optional steps from 11 onwards just like a real project. By the end of step 17 it will look like this:
AWS provides many options to store and query data. For the type of data that we want to store in our tracking application, a database is probably most appropriate and AWS provides severeal managed and unmanaged services. While the recently announced Amazon Aurora Serverless might be an option in the future, we'll pick for now the already proven NoSQL database Amazon DynamoDB.
Head over to step 1 to dive right in.
AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no charge when your code is not running. Lambda truely simplifies the development as long as your code meets the requirements, i.e. if you're developing APIs that don't require more than 5 min of execution time or 3 GB of memory it is pefect to get started quickly, avoid the management of servers and save cost. It is outside the scope of this workshop but for more complex scenarios where you may want to orchestrate multiple Lambda functions, have a look at AWS Step Functions.
For now head over to step 2 to create your Lambda function.
Amazon API Gateway is a service that enables developers to create, publish, maintain, monitor, and secure APIs at scale. You can create APIs that access AWS or other web services, as well as data stored in the AWS Cloud. There are several ways to athorize access to the API, including a simple API Key system with usage plans that allow you to throttle API requests. For this workshop you will take advantage of these usage plans to authorize access to the API.
So, head over to step 3 to set up the API Gateway and create a method that triggers the Lambda function, you created in the pevious step.
As mentioned in the requirements, your machine should be prepared for the development of Apache Cordova applications and if you build on a Mac and deploy to iOS you will find more details on how to set up the machine in appendix 4.
If you are ready to work with Apache Cordova, head over to step 4.
There are several good mapping services you can choose from when adding an interactive map to an Apache Cordova application: Mapbox, Bing Maps, Google Maps, HERE or TomTom to name a few. Of course you can also use open data such as OpenStreetMap to run your own mapping services. In fact, if you only want to serve maps, as we do in this workshop, it isn't all that difficult and may in fact be more cost efficient than a 3rd party mapping services. Perhaps, we look at this in an optional step later on. For now you'll work with Mapbox, a great service from a great company with lots of open source projects here on GitHub that has done some phenomenal work leveraging and contributing to OpenStreetMap and other related open source and open data projects.
Head over to step 5 to integrate Mapbox into your Cordova application.
Amazon S3 provides object storage with 11 9's of durability and can be easily configured to serve static websites. In the spirit of serverless application that's an ideal scenario for us.
Navigate to step 6 to get started.
For the authentication and authorization of access to your website you will use Amazon Cognito. Cognito scales to millions of users, and supports sign-in with social identity providers such as Facebook, Google, and Amazon as well as enterprise identity providers via SAML 2.0. For this workshop you will work with Cognito User Pools rather than federating with identity providers.
Navigate to step 7 to dive right in.
In the previous 2 steps you have created your website and configured a Cognito User Pool to manage authentication and authorization. It is now time to configure your website to make use of the user pool.
Navigate to step 8 to modify your website.
With the structure and user management for your website in place, the final piece is to create an API that retrieves data from your DynamoDB table and displays it on the map. Creating the API is very similar to what you have already done in step 2 and 3. Therefore we'll go through this a bit quicker.
Head over to step 9 to dive right in.
The code for your website is already prepared to call your newly created API but you still need to make a modification to config.js to provide the Invoke URL for your API Gateway and a key. In step 10 you will make this final change.
Amazon CloudFront is a content delivery network (CDN) that delivers data, applications and APIs to end users worldwide with low latency and high transfer speeds. CloudFront is integrated with AWS infrastructure and services and takes advantage of AWS Shield for DDoS mitigation. The latter is quite relevant not just to keep your website available but also to prevent excessive cost that such a DDoS attack could cause.
Note: The API Gateway is by default already integrated with CloudFront.
Head over to step 11 to provide a global presence, faster response times and DDoS protection to your website.
Amazon Route 53 is a highly available and scalable Domain Name System (DNS). Aside from registering domains and resolving domain names to IP v4 and v6 addresses inside and outside of AWS, it can also be used to perform health checks, fail-over between entire regions or to provide different types of routing such as latency-, weighted round robin- or geographic proximity-based routing.
We won't cover region failover and different types of routing in this workshop but head over to step 12 to register your domain and point it to your CloudFront distribution.
To some extend it is a matter of taste if you have a domain with or without the prefix www - or both. If you want to have them both, head over to step 13 next.
Sending sensitive data such as your user ID or a password over the open internet is a recipe for disaster. In this final step you will create a SSL/TLS certificate using the AWS Certificate Manager to secure your website.
As you start using the application, you'll discover many things you'd like to improve and come up with new ideas you want to implement as well. For example:
In the next steps we go through a few of those and introduce additional features and technologoes along the way. In step 15 we look at the first 2 bullet points. To create a device table you will be Customizing Cognito User Pool Workflows by Using AWS Lambda Triggers.
During this workshop you have already configured a custom domain name for your web application but the APIs are still using less memorable automatically generated URLs such as https://api-id.execute-api.region.amazonaws.com/stage. In this step we will change this and set up a custom domain for your APIs.
One of the things you identified above as a significant feature to add was the trip detection. You want to get from individual GPS traces that are streaming in location by location to a point where you can identify trips with start- and end-time, mileage etc. This seems like a good time to also introduce routine tasks such as backup and cleaning up the raw trace data. These tasks can be easily implemented in just one Lambda function but since there is a few things that should be orchestrated in a certain sequence and triggered in regular intervals this is a good time to think about de-coupling of tasks and implementation of workflows. While there are several options such as coding it yourself or Amazon Simple Workflow Service (SWF), a great vehicle for serverless applications are AWS Step Functions. Head over to step 17 to find a simple implementation.