We have completed setting up the infrastructure. Now, we just need to deploy the Go application to the EC2 instance to complete the lab! xd
workshop-01
│───assets # Contains images used in the project
│
└───static # Contains static files
│ └───css # Stores CSS files for styling
│ │ styles.css
│
└───templates # Stores HTML templates
│ │ article.html # Template for displaying an article
│ │ base.html # Base template used across other templates
│ │ edit.html # Template for editing an article
│ │ index.html # Template for the homepage
│ │ new.html # Template for creating a new article
│
│ .env.example # Example environment variables file
│ .gitignore # Git ignore rules for the project
│ db.go # Contains logic for database interactions
│ go.mod # Specifies Go module version and dependencies
│ go.sum # Contains checksums for dependencies
│ main.go # Main application logic, includes rendering and CRUD operations for articles
│ README.md # Documentation for the project
$ sudo yum install git -y
$ git --version
$ wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz
$ sudo tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin
$ go version
$ git clone https://github.com/minhnghia2k3/workshop-01.git
Add the required environment variables for the application:
$ vi ~/.bashrc
export DATABASE_URL="admin:Admin123@tcp(<YOUR_DB_ENDPOINT>:3306)/blog_db"
export AWS_REGION="ap-southeast-1"
export S3_BUCKET_NAME="minhnghia2k3-blog-s3-bucket"
$ source ~/.bashrc
$ ls
$ cd workshop-01
$ go build -o ./bin/main .
$ ./bin/main
From the EC2 SSH terminal:
1. Check MySQL:
$ mysql -h mysql-golang-db.c1a20mqwgeb9.ap-southeast-1.rds.amazonaws.com -P 3306 -u admin -pAdmin123
$ USE blog_db;
$ SELECT * FROM articles;
id | title | content |
---|---|---|
1 | Introduction to Golang: A Beginner’s Guide | Golang, or Go, is an open-source programming language designed by Google. Known for its simplicity, concurrency support, and performance, Go is an excellent choice for building scalable web applications, cloud-native solutions, and microservices.fmt.Println("Hello Go!") |
2. Check the Bucket: