Skip to content

"Image Filtering App" with NodeJs is a cloud application developed and hosted on AWS ElasticBeanstalk. It allows users to download images from a publicly accessible address. It validates the public accessibility of the URL with queries and process photos using an image filtering microservice API.

License

Notifications You must be signed in to change notification settings

eedygreen/Full-Stack-Apps-in-AWS

Repository files navigation

README.md

IMAGE FILTERING MICROSERVICE with NODEJS

"Image Filtering Microservice" with NodeJs is a simple cloud application developed and hosted on AWS ElasticBeanstalk alongside the Udacity Cloud Engineering Nanodegree. It allows users to download images from a public accessible address. It validate the public accessibility of the URL with queries, post photos to the feed, and process photos using an image filtering microservice.

The Steps below is targeted towards readers with knowledge of Git, AWS ElasticBeanstalk, Typescript programming, NodeJs, Node Package Manager (npm), Linux, and DevOps principles.

Image Filter Microservice App

The image-filter url app is built with express web framework on nodejs.

See the code

Engineering Process and Quality

Following good cloud practices, development and production environment created for this project. All code written, build processes and deployment were done on Dev environment. The Git & GitHub Dev environment served as the working, testing, staging and deployment env before merging the updated working code to main branch. The main branch contains the most recent working and tested solution.

Development Server

  • Install the dependencies npm i npm install

Fig 1.0: Installing Dependencies



  • Switched to dev branch to commit and test the node server for dev environment

npm run dev

npm run dev

Fig 2.0: Dev Server Running



  • The API design and Implementation

IMPLEMENT A RESTFUL ENDPOINT GET /filteredimage?image_url={{URL}} endpoint to filter an image from a public url. IT SHOULD

  1. validate the image_url query
  2. call filterImageFromURL(image_url) to filter the image
  3. send the resulting file in the response
  4. deletes any files on the server on finish of the response QUERY PARAMATERS image_url: URL of a publicly accessible image RETURNS the filtered image file [!!TIP res.sendFile(filteredpath); might be useful] /**************************************************************************** */

see the code here

Image Url Validator

//Image Url validator code
const url_regex    = new RegExp(/([a-z]+\:\/+)([^\/\s]+)([a-z0-9\-@\^=%&;\/~\+]*)[\?]?([^ \#\r\n]*)#?([^ \#\r\n]*)\.(?:jpeg|jpg|gif|png|svg|bpm|tiff)/ig);
    const is_Valid_url  = url_regex.test(image_url);

Testing The API with POSTMAN

  • Status Code 422 Testing the API with POSTMAN for graceful failure.

    catch(error) {
          return res.status(422)
                    .send(`${image_url} format not supported! See Supported formats: jpg, png, bmp, tiff, or gif`);
        }

    It failed as expected. The url validator only checks for a valid url with condition; publicly accessible and image file type. While the image filter checks if this is a supported format.

image_processed_status_422

Fig 3.0: Status Code 422



  • Status Code 200
try {
      //2.  calling the filterImageFromUrl function to validate the image
      const filter_image_file: string = await filterImageFromURL(image_url);
      
      //3.  sending the resulting file from filterImageFromUrl function
      res.status(200).sendFile(filter_image_file);
      
      //4. Deleting the file from the local tmp/filtered directory
      res.on('finish', () => deleteLocalFiles([filter_image_file]));
    }

It passed the testing as expected

image_processd_status_200

Fig 4.0: Status Code 200



ElasticBeanStalk Deployment

  • Build the Application
npm run build

npm_run_build

Fig 5.0: Build the Application



  • Initiate the ElasticBeanstalk Application
eb init --platform node.js --region us-east-1

Reb_init

Fig 6.0: Initialised ElasticBeanstalk



  • Create the ElasticBeanstalk Environment
eb create --sample full-stack

eb_create

Fig 7.1: Create ElasticBeanstalk



  • ElasticBeanstalk Dashboard

ElasticBeanstalk_created

Fig 7.2: ElasticBeanstalk Dashboard



  • Testing Full-Stack Endpoint

elasticbeanstalk_endpoint

Fig 8.0: Full-Stack Endpoint



  • Deployment
eb deploy

Fig 8.0: ElasticBaeanstalk Deployment

eb_deploy_app

Fig 9.1: ElasticBeanstalk Deployment

app_deployed

Fig 9.2: ElasticBeanstalk Deployment - Dashboard

  • Response to Public URL

endpoint_downloading_link

Fig 10.1: Filteredimeage download the public image



  • filteredimage Endpoint

endpoint_elasticbeanstalk_download_image

Fig 10.2: filteredimage

![filteredimage]http://full-stack.eba-3tfrxr3e.us-east-1.elasticbeanstalk.com/filteredimage?image_url=https://bs-uploads.toptal.io/blackfish-uploads/blog/post/seo/og_image_file/og_image/15921/secure-rest-api-in-nodejs-18f43b3033c239da5d2525cfd9fdc98f.png

cat

Fig 11.1: Cat

Public URL

https://upload.wikimedia.org/wikipedia/commons/b/bd/Golden_tabby_and_white_kitten_n01.jpg

ElasticBeanstalk Public URL

http://full-stack.eba-3tfrxr3e.us-east-1.elasticbeanstalk.com/filteredimage?image_url=https://upload.wikimedia.org/wikipedia/commons/b/bd/Golden_tabby_and_white_kitten_n01.jpg

Public URL

http://full-stack.eba-3tfrxr3e.us-east-1.elasticbeanstalk.com

The ElasticBeanstalk Public URL

http://full-stack.eba-3tfrxr3e.us-east-1.elasticbeanstalk.com/filteredimage?image_url=https://upload.wikimedia.org/wikipedia/commons/b/bd/Golden_tabby_and_white_kitten_n01.jpg

Problems Encounter and Solution

To be written later

Summary

The ImageFilter App is an application developed with express framework hosted on elasticbeanstalk. Code written for this work were structured into directories. The API is written with Typescript in server.ts file which is located at the image-filter-starter-code/src directory.

About

"Image Filtering App" with NodeJs is a cloud application developed and hosted on AWS ElasticBeanstalk. It allows users to download images from a publicly accessible address. It validates the public accessibility of the URL with queries and process photos using an image filtering microservice API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages