"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.
The image-filter url app is built with express web framework on nodejs.
See the code
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.
Fig 1.0: Installing Dependencies
- Switched to dev branch to commit and test the node server for dev environment
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
- validate the image_url query
- call filterImageFromURL(image_url) to filter the image
- send the resulting file in the response
- 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);
-
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.
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
Fig 4.0: Status Code 200
- Build the Application
npm run build
Fig 5.0: Build the Application
- Initiate the ElasticBeanstalk Application
eb init --platform node.js --region us-east-1
Fig 6.0: Initialised ElasticBeanstalk
- Create the ElasticBeanstalk Environment
eb create --sample full-stack
Fig 7.1: Create ElasticBeanstalk
- ElasticBeanstalk Dashboard
Fig 7.2: ElasticBeanstalk Dashboard
- Testing Full-Stack Endpoint
Fig 8.0: Full-Stack Endpoint
- Deployment
eb deploy
Fig 8.0: ElasticBaeanstalk Deployment
Fig 9.1: ElasticBeanstalk Deployment
Fig 9.2: ElasticBeanstalk Deployment - Dashboard
- Response to Public URL
Fig 10.1: Filteredimeage download the public image
- filteredimage Endpoint
Fig 10.2: filteredimage
Fig 11.1: Cat
https://upload.wikimedia.org/wikipedia/commons/b/bd/Golden_tabby_and_white_kitten_n01.jpg
http://full-stack.eba-3tfrxr3e.us-east-1.elasticbeanstalk.com
To be written later
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.