In Chapter-10 of our Golang Tutorial, we touched upon ‘Go with GORM’. In this chapter, let’s explore ‘Deploying Go App on AWS EC2 Server’.
So everybody knows what is Cloud Computing? What is AWS i.e.Amazon Web Services? So basically Cloud Computing is nothing but its like to hire someone to host our application on the internet. They will provide the infrastructure on the basis of the amount paid. It is like a stay in the house by paying rent.
So Google, Amazon, Microsoft are the biggest giants in the cloud computing sector. They provide large infrastructure and services to run your web stuff.
Amazon Web Services (AWS) offers cloud computing infrastructure by leading giant Amazon Inc. that provides on-demand computing platform. These AWS are offered in almost every region in the world. It includes Amazon Elastic Compute Cloud (EC2).
AWS has more than 70+ services including compute, storage, networking, database, analytics, app services, deployment, management, mobile, developer tools and tools for IoT.
Here, I have installed Ubuntu 16.04 LTS. Go here After installing Ubuntu, open terminal by pressing Ctrl+T and enter a command
$sudo apt-get update
$sudo apt-get -y upgrade
Then, download the latest version of Go by
$sudo curl -o https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
Next use tar to unpack the package. This tool will open and extract downloaded file, and create a folder using package name and then move it to /usr/local
$sudo tar -xvf go1.8.3.linux-amd64.tar.gz
$sudo mv go /usr/local
You can also install this Go in another folder. Here now, Go package is in /usr/local folder and it is now in $PATH for Linux.
Now, set your Go paths needed for Go project. So to set the Go paths you need to set it into .profile file. It is like setting environment variables in windows.
First, open this .profile file by entering below command
$sudo nano ~/.profile
At the end of this file add the below lines
export GOROOT=/usr/local/go [Installation path]
export GOPATH=$HOME/GoDemo [Workspace path]
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH [bin directory of both]
$sudo nano ~/.profile
After this check whether Go setup is done completely or not by entering a command
$go version
If it is showing the version of the installed Go library then it means your setup is ready to develop go applications.
We need to create an AWS EC2 (Elastic Compute Cloud) instance in order to host our application on the AWS cloud and we need to pay for that. You can purchase it from their official website.
Once we have instance we can create Amazon Machine Instance in AMI(Amazon Machine Image)
Prebuilt machines will show Choose an Amazon Machine Image if already you used.
Choose AMI
Choose the machine – for ex. Ubuntu Server 26.4 LTS(HVM)
Choose Instance Type
Choose “t2.micro” . Just Google the pricing of t2.micro. It is intended to provide high performance required by your workload
Configure Instance Details
Add Tags
Key value pair kp-28-08-2017
Security Group
Assign security group, who can be able to access this machine, Here I’ve taken ssh access.
SSH
HTTP
Will create PEM file (Public Private Key Encryption which is asymmetric encryption) and download it. So your complete instance will be created.
Note: I’ve never created the EC2 instance, so you can check more from other sources. I’ve used my organization’s ec2 instance.
Now, here is the process of deployment of Go application on the ec2 instance using a Linux environment.
1. Public DNS Or Ec2 IP (Any Of This)
2. Pem File
Now, we’ll look into the deployment process.
Download Pem File And Move It To .Ssh Folder
Download the .pem file from ec2 instance and move it to .ssh folder
$ mv ~/Downloads/go.pem ~/.ssh/
If .ssh folder is not present in your system then you need to create in manually and then move it. Here, I downloaded .pem file and moved it to .ssh folder
$mkdir .ssh
Now, set the permission on .pem file which is just moved to ssh folder
Build Your Binary
As we have already installed Go on the system. Here, create one go application in your workspace.
I’ve created go application in my workspace at below path
GoDemo/src/Mindbowsers/MBIS/main/main.go
Now we’ll build a binary.
So in order to build the binary using Linux environment, you need to set OS variables like GOOS=linux and GOARCH=amd64.
GOOS→ Operating System GOARCH→ Architecture
You need to set it by going to the main folder of a project where your main.go resides
$go env
This command will show you all environment related to Go.
GOOS=operating system GOARCH=architecture
So, now run below command to build your binary.
$GOOS=linux GOARCH=amd64 go build -o GoDemoProject
“GoDemoProject” is the name I’ve given. You can give any name.
After entering the command, just go and check to the main location if their binary got created.
Copy Binary To Server
In order to copy your binary to the server, you need to use the scp i.e. secure copy command.
The specifications of the command are as given below.
$scp(secure copy) -i ~/.ssh/go.pem(PEM file path) GoDemoProject(binary name) ec2-user@publicDNS:
So, the command will be like this for me,
$scp -i ~/.ssh/go.pem GoDemoProject ec2-user@13.57.33.139:
Your application will be uploading to ec2 server. ec2-user might be Ubuntu depending on your machine
SSH Into Your Server
The specifications are like this
$ssh(Secure Shell) -i ~/.ssh/go.pem(pem file location) ec2-user@publicDNS:
you will be remotely connected to aws
ec2-user@ip-172-31-1-173
Run Your Application
Before running your application, give the rwx (Read Write Execute) permissions to the application. Check your binary has executed permission by entering command
ec2-user@ip-172-31-1-173:$ls -la
Change the permission
ec2-user@ip-172-31-1-173:sudo chmod 700 GoDemoProject
Now here run your application by specifying a name
ec2-user@ip-172-31-1-173:$sudo ./GoDemoProject
For disconnecting with the remote server just press exit command. You will be disconnected from the remote server.
How to Effectively Hire and Manage a Remote Team of Developers.
Download NowMindbowser played a crucial role in helping us bring everything together into a unified, cohesive product. Their commitment to industry-standard coding practices made an enormous difference, allowing developers to seamlessly transition in and out of the project without any confusion....
CEO, MarketsAI
I'm thrilled to be partnering with Mindbowser on our journey with TravelRite. The collaboration has been exceptional, and I’m truly grateful for the dedication and expertise the team has brought to the development process. Their commitment to our mission is...
Founder & CEO, TravelRite
The Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
Mindbowser has truly been foundational in my journey from concept to design and onto that final launch phase.
CEO, KickSnap
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork