Showing posts with label aws. Show all posts
Showing posts with label aws. Show all posts

Tuesday, July 14, 2020

AWS workshop in HCMC - Kubernetes on AWS with Amazon EKS

I attended the workshop on Jul 14 2020

Summary the of the workshop


I have learned a new term of CDK - Cloud Development Kit,

They use Cloud9 - An online VS Code version to code the CDK, we practiced creating an infrastructure using TypeScript

https://cdkworkshop.com/20-typescript.html


Wednesday, December 5, 2018

How to deploy NodeJS ReactJS to AWS EC2

I am working on a web application, which BackEnd is in NodeJS, FrontEnd is ReactJS Single Page Web Application.

I want to deploy the application on AWS EC2, Here is how I did it.

2018-12-05-00-19-12
Client - Server overview

 NodeJS

node version : v10.13.0

npm version : 6.4.1

BackEnd application runs on port 3000

I use PM2 for  process manager for Node.Js http://pm2.keymetrics.io/

ReactJS

React-scripts : 2.1.1 is ReactJS development tool, also help us to bundle javascript, css, images... into a build folder.

NGINX

Version : nginx version: nginx/1.14.0 (Ubuntu) , to find ngnix version
Change  nginx default file: /etc/nginx/sites-enabled/default

1. Add proxy pass for API
location ~ ^/api/ {
   proxy_pass      http://127.0.0.1:3000;
}

to pass all API requests to NodeJS server.

2. Add root static folder
root /home/ubuntu/public_html/lime-fe/build;

To point default static folder to the build folder of react-script.

3. Also it is important to have

location / {
    try_files $uri /index.html;
}
4. Reload nginx sever:
 
# systemctl restart nginx
OR
# sudo systemctl restart nginx
5. Additional setups: - Remove nginx version
server_tokens off;
- Enable Gzip
        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        

to let reactJS application handles the routing (URLs) instead of nginx.

Full configuration file.


Setup environment variables

~/.bash_profile

Some variables :

export NODE_ENV=production

To reload bash environment, using the command

source ~/.bash_profile

OR
. ~/.bash_profile

Some notes:

1. npm install without devDependencies:

If server setup with production mode on

NODE_ENV=production

, NPM install will ignore devDependencies

We can use npm install --only=dev or set NPM production.

to check if npm is in production mode , we can use the command:

npm config get production

To turn off production mode:

npm config set -g production false

2. pm2 doesn’t reload environment variables:

we need to use --update-env ,
e.g:
 pm2 reload sever --update-env

References

  1. How to install NodeJS and NPM : https://github.com/nodesource/distributions/blob/master/README.md

  2. How to install
    https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04

  3. How to check Ubuntu version: https://askubuntu.com/questions/686239/how-do-i-check-the-version-of-ubuntu-i-am-running

  4. How to install MongoDB on Ubuntu: https://docs.mongodb.com/v3.2/administration/install-on-linux/

Monday, June 18, 2018

Cài đặt Elastic IP address cho server EC2 trên AWS

Tại sao lại cần phải dùng đến Elastic IP Address.

Khi bạn tạo một EC2, AWS mặc sẽ cấp cho bạn một địa chỉ IP (Public IP Address), nhưng nếu máy chủ của bạn gặp trục trặc bạn phải stop rồi reboot EC2, trong trường hợp này AWS sẽ gán một địa chỉ Public IP khác cho máy EC2 của bạn.

Mọi việc sẽ không có vấn đề gì, nếu như bạn không trỏ một domain đến địa chỉ Public IP mà AWS đã cung cấp.

Trong trường hợp bạn đã trỏ domain của bạn đến Public IP thì khách hàng của bạn sẽ không truy cập được server của bạn nữa vì Public IP đã đổi đến địa chỉ khác.

Đừng lo lắng, AWS đã cung cấp một giải pháp để khắc phục trường hợp này. Đó là ngay sau khi bạn tạo máy chủ EC2. Hãy tạo gán ngay cho nó một địa chỉ Elastic IP Address.



  1. Bạn chọn vào Instance rồi chọn Manage IP Addresss

1-2018-06-18-16-31-15

2. Chọn vào Allocate an Elastic IP
2-2018-06-18-16-31-37

3. Chọn allocate để tạo 1 địa chỉ mới.

3-2018-06-18-16-32-08

4. Một địa chỉ mới đã được cấp cho bạn.2018-06-18-16-32-21

5. Chọn vào action để gán địa chỉ cho một EC2.

2018-06-18-16-32-35



6. Chọn vào Associate address

2018-06-18-16-32-48

7. Chọn Instance ( Máy chủ EC2 đã được tạo)2018-06-18-16-33-20

8. Quay lại máy chủ EC2 và kiểm tra lại địa chỉ IP2018-06-18-16-34-49



Và bây giờ bạn có thể Stop hoặc Reboot server EC2 thoải mái.