Skip to content

yuriechan/amazon_authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Simple Web Server responding to GET requests

I built a web server with Node.js/Express on top of AWS EC2.
The application returns a response to the GET request from the client.
This project was part of Amazon Cloud Engineer Technical Test.

Available endpoints

  • / returns AMAZON if request was successful (Below is a sample IP address)

    • run $ curl "http://1.2.3.4/"
  • /secret validates basic authentiation with { login: 'amazon', password: 'candidate' }

    • running $ curl -u amazon:candidate "http://1.2.3.4/secret/", returns SUCCESS
    • running $ curl "http://1.2.3.4/secret/", returns authentication fail message
  • /calc

    • running $ curl 'http://1.2.3.4/calc?1+2*3', returns 7
    • running $ curl 'http://1.2.3.4/calc?2-1', returns 1
    • running $ curl 'http://1.2.3.4/calc?3*2', returns 6
  • /stocker

    • running below returns xxx: 96
    $ curl "http://1.2.3.4:8080/stocker?function=deleteall"
    $ curl "http://1.2.3.4:8080/stocker?function=addstock&name=xxx&amount=100"
    $ curl "http://1.2.3.4:8080/stocker?function=sell&name=xxx&amount=4" 
    $ curl "http://1.2.3.4:8080/stocker?function=checkstock&name=xxx"
    
    • running below returns xxx: 96 yyy: 100 YYY: 100
    $ curl "http://1.2.3.4:8080/stocker?function=addstock&name=yyy&amount=100"
    $ curl "http://1.2.3.4:8080/stocker?function=addstock&name=YYY&amount=100"
    $ curl "http://1.2.3.4:8080/stocker?function=checkstock"
    

Below are the functions implemented for /stocker
(1) Addition of inventory

  • argument:
    • function (required): addstock
    • name (required): Specify the name of the target product.
    • amount (arbitrary): Specify the number (positive integer) to add the target product to the inventory. The default is 1.
  • Output: None

(2) Inventory check

  • argument:
    • function (required): checkstock
    • name (optional): Specify the name of the target product.
  • Output:
    • If a name is specified, the number of items in stock with that name is output in the "[name]: [amount]" format. When there is no stock, amount is displayed as 0.
    • When name is not specified, the number of stocks of all products is sorted in ascending order with name as a key and output. Items with 0 inventory are not displayed.
  • Example output:
    • xxx: 12
    • yyy: 7

(3) Sales

  • argument:

    • function (required): sell
    • name (required): Specify the name of the target product.
    • amount (arbitrary): Specify the number (a positive integer) of the target product sold. The default is 1.
    • price (optional): Specify the price of the target product (a number greater than 0). Only when input, add price x amount to sales.
  • Output: None

(4) Sales check

  • argument:
    • function (required): checksales

    • Output: Displays the current sales in the format "sales: [sales]". For decimal numbers, round up to the second decimal place.

  • Example output:
    • sales: 400

(5) Delete all

  • argument:

    • function (required): deleteall
  • Output: None

A Learning Experience

It was my first time connecting to a remote computer through SSH.
I learned how to use vim, and play around with requests and responses over HTTP.

Development

  • Please replace the IP address on app.js, with your IP address to run on localhost.
  • run node app.js to start the web server

About

Amazon's Cloud Engineer Technical Test 2020

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published