This assignment solution is the implementation of a web application using a technology stack that meets Cloud-Native Web Application Requirements. It uses Express (a Node.js web application framework) to build the web application.
npm install
npm start
npm test
The application uses express module's router
to create the routes and uses http
module to create the http server (exposed at port 3000). The application implements the api specified in the Swagger Doc. The application uses jest
and supertest
modules to run unit tests to validate the endpoints and few other scenarios. The application returns proper http status codes based as per Http Status Codes
A proper .gitignore
is created for ignoring node & vscode related build and config files which are not necessary to be checked in to the version control.
When we run this application using the npm start
command, it starts the server locally, available at http://localhost:3000
which cab be tested via postman.
An automated workflow is created via github actions to run the unit tests via the file node.js.yml
which has jobs to create node js environment in ubuntu os. Then it installs the node application and runs all the tests. This action is triggered whenever a pull request or push to main branch is done.
Also, branch protection is added in the upstream repo where unless all the workflows run successfully, it doesn't allow the Pull Request to merge to the main branch.
This assignment solution includes the followings technology and commands:
-
A Token-based web authentication called
basic authentication
is used at the authenticating end point, for the user to access the page -
password hashing
technology is used to hash the password and save in the database -
salt
is used to retrieve the passwords from hashed passwords, from the database when a user is trying to login/authenticate -
npm install --save bcrypt
is used to install the dependencies for the above said feature to be functional -
MySQL
is used as the relational database andSequilize
is used as the ORM(object relational mapping) tool, this tool to map and communicate between objects and relational database systems. This provides good flexibility in connecting, storing and accessing the data -
npm install --save sequilize
andnpm install --save mysql2
are the commands used to install and save the dependencies related to sequilize and mySQL
-
Every time when a user is
create
d, the valid username, hashed password, first_name, last_names, createdAt(Time and Date) and updatedAt(Time and Date) are saved in db. -
For every
GET
method the user has to provide the username and password as an authentication. The hashed password saved in the db will be then decrypted andcompared
with thepassword(Entered by the user)
. If that matches, then login issuccessful
otherwise returns an errorunauthorized user
-
To
Update
any fields in the user information, first the login should be legit. What I mean is, the user details should be present in the db, Later if the user wants change any fields (password
,first_name
andlast _name
fields only) can be allowed.
- Using the packer file format, aws-ami.pkr.hcl is written, To add show the same AMI in demo account
ami_users
properties also used in source of the file. - We need to install MySQL, node.js, unzip in the Vm we are creating, therefore we need to include the commands to do the same in our packer as well. scripts (.sh) file has all the commands those will install the required applications and packages.
- Any special variables can be saved in the
packervariables.json
file - To format the file use
packer fmt .
command. - To validate the packer use
packer validate .
- To run the packer file use
packer build aws-ami.pkr.hcl
- To run thr packer with variable parse the argument
packer build -var-file='/Users/soumyanayar/NEU/Spring 2022/Cloud Computing/webservice/packervariables.json' aws-ami.pkr.hcl
- To automate the AMI building in the AWS console enable the github actions when pull request merges with main branch
- Go to the AWS EC2 console and check for AMI(Private) and copy the
ami-id
- Go to
infrastructure
repo and paste theami-id
in the AMI parameter - And deploy the cloudformation using
aws cloudformation deploy --profile dev --stack-name final1 --region us-west-2 --template-file ./csye6225-infra.yml
- Go the instance that runs with the
stack-name
and copy thepublic_ip_address
- Now got the
postman
app and passpublic_ip_address:3000/healthz
and other end points to check whether the web application is running
- New API
POST
for/v1/user/self/pic
will let an authenticated user to upload a profile picture GET
for/v1/user/self/pic
will get the profile picture for the authenticated userDELETE
for/v1/user/self/pic
will delete the profile picture$ npm install --save multer
command to install the multer package. This will allow us to do the GET, POST and DELETE operation on image's URL saved in S# bucket of AWS- Removed the locally installed MYSQL, RDS Instance in AWS will be used to save the data from the web application
- Used
aws-sdk/clients/s3
to make a call to s3 bucket and the same is installed usingnpm install @aws-sdk/client-s3
.
- Load testing is added to the repo to test the load balancer
- Installing the Code Deploying Agent in AMI packer file
- A S3 bucket is created in AWS console and has the policy to store the artifacts generated.
- AWS CLI for importing the certificate
aws acm import-certificate --certificate fileb://demo_soumyanayar_me.crt --certificate-chain fileb://demo_soumyanayar_me.ca-bundle --private-key fileb://private.key --region us-west-2