Back to Projects

Dragons

Complete
AWS LambdaAmazon Step FunctionsAPI GatewayAmazon CognitoAWS X-Ray

Project Overview

The sole purpose was to keep track of dragon sightings around the globe. When a dragon is spotted, we use the POST method to add it to our list of found dragons and add its complete description and its origin/region of sight. A text message is sent confirming it has been added. If the dragon already exists, an error is raised and a text message notifying the user of its existence is delivered. The GET request allows us to view our list of dragons as well. The project was done entirely on AWS, though there was an alternative to do it locally by using the AWS toolkit on IntelliJ IDE, installing AWS CLI, configuring AWS Serverless Application Model (SAM), an open-source framework for building serverless applications and installing Docker as a prerequisite

Workflow

The Dragons application implements a serverless architecture using AWS services. The workflow begins when a user submits a dragon sighting through the web interface. This triggers an API Gateway endpoint, which invokes a Lambda function to process the submission. The Lambda function validates the data and checks for duplicates in DynamoDB. If the dragon is new, it's added to the database, and a Step Function workflow is initiated to process the sighting. This workflow includes sending an SMS notification via SNS, storing images in S3, and updating the dragon catalog. The entire process is monitored using AWS X-Ray for distributed tracing, allowing us to identify bottlenecks and optimize performance. Authentication is handled by Amazon Cognito, ensuring that only authorized users can submit and view dragon sightings.

Dragons Workflow Diagram

API Gateway GET Method Execution

This diagram shows the complete flow of a GET request through API Gateway to retrieve dragon sightings. The method uses Cognito for authentication and implements a Lambda proxy integration. When users request to view dragons, the API Gateway validates the request, forwards it to the Lambda function, and returns the list of dragons in JSON format with a HTTP status code 200 OK. The proxy integration allows for flexible response handling and maintains the serverless architecture's efficiency.

API Gateway GET Method Execution

API Gateway POST Method Execution

This diagram illustrates the POST method execution flow for adding new dragon sightings. The process involves authentication through Cognito, validation of the dragon data, and integration with AWS Step Functions for complex workflow orchestration. When a new dragon is submitted, the API Gateway processes the request, triggers the Lambda function for validation, and initiates the Step Functions workflow that handles duplicate checking, data storage, and notification sending through SNS.

API Gateway POST Method Execution

Step Functions State Machine Workflow

This state machine diagram details the Step Functions workflow that orchestrates the dragon submission process. The workflow starts with ValidateDragon to ensure data integrity, then proceeds to AddDragon for database storage. The ConfirmationRequired state acts as a decision point that branches into different notification paths. Error handling is implemented through AlertDragonValidationFailure and CatchAllFailure states, ensuring robust error management. Success scenarios are handled by either AlertAddDragonSuccess (with SMS notification) or NoAlertAddDragonSuccess (silent success), providing flexible notification options based on user preferences or system configuration.

Step Functions State Machine Workflow

Dragons Perks

A loosely coupled architecture for the POST method which does not affect other services when being updated or deleted. Note we could just have combined the two lambda functions, it would still work but when updating the function code in future, we would probably have updated the entire code. This is the sole-purpose of Step Functions in this architecture. A serverless WebApp. I don't necessarily have to care about provisioning or maintaining my backend servers or workflows of the entire infrastructure, therefore lowering transaction costs through auto scaling. An organisation definitely loves a cost optimised infrastructure! API Caching. Make fewer GET requests to Lambda functions. Using this feature greatly optimises for latency, and potentially for cost (when you factor in the costs of your backend infrastructure). If we look at security, we have to consider encryption at rest and in transit Lambda endpoints only support secure connections over HTTPS at the transport layer when in transit. CORS (Cross-Origin Resource Sharing) is also enabled to allow access of other domains or ports other than its own in API Gateway. Method requests to the app can only be sent by Cognito authenticated users.

Features

  • AWS SDK for Java
  • Gradle for managing dependencies and build
  • Cloud9 IDE already configured with AWS CLI

Technologies Used

  • Amazon API Gateway for serverless REST API hosting
  • AWS Lambda for serverless compute
  • Amazon Cognito for serverless authentication
  • AWS Step Functions for serverless orchestrating workflows for Lambda functions
  • AWS X-Ray for distributed tracing of workflows across the POST method

Project Details

Help Me Improve

Have suggestions, feedback, or a different perspective? I value your input! It helps me shape better work and improve as a developer.

Contact Me