/aws-node-crud-api

node crud api deployed to aws using code deploy

Primary LanguageJavaScript

Nodejs Crud Api Deployed on AWS

This is a tutorial on how to use aws service EC2 and CICD tools Code pipeline and Code deploy

1. Setup Source

a. Create Repo add source code to it
  b. Add scripts within scripts folder
  - application_stop.sh
  - before_install.sh
  - application_start.sh 
note scripts are listed in order of execution  
c. create appspec.yml file

2. Setup Aws Iam Roles

a. Create Role for CodeDeploy (CodeDeployRole)
b. Create Role for EC2 (EC2CodeDeployRole)

3. Setup EC2 Instance

a. Select Amazon Linux 2 Instance Type should be t2.micro
b. Create a Key Pair for SSH
c. Add security group rule to allow HTTP traffic on port 80
d. Add security group rule to allow HTTP traffic on port 3000
e. For IAM Instance Profile select (EC2CodeDeployRole)
f. Add code deploy agent script in user data text area (see scripts folder)
g. Add tag to ec2 before launch (DO NOT SKIP THIS STEP !)

4. Setup CodeDeploy

a. Create application in CodeDeploy (name it and select EC2/On Premises) 
b. Create deployment group (name it and give it the role of CodeDeployRole) 
c.Select In-place for Deployment Type
d.Select Amazon EC2 Instance for Environment Configuration
e.Select your tagged EC2 instance
f.Leave all other configurations as default EXCEPT for the Load Balancer (disable that option)
g. Create Deployment Group when all previous steps are complete

5. Setup CodePipeline

a. Name your pipeline
b. Select your source repo as Github (Version 2)
c. Create new Connect with Github and Authenticate
d. Select desired repository 
e. Select desired branch 
f. Skip build stage 
g. For deploy stage select CodeDeploy as your provider
h. Select previously created CodeDeploy Application and Deployment Group 
i. Once all previous step are completed create pipeline