Some useful commmands you will need to build your goloang binary and deploy to aws-ec2
$ GOOS=linux GOARCH=amd64 go build -o [binary-name]
- type
go env
to check your environment variables GOOS
stands for Go OS, depends on what ec2 machine you rent, you might have different os settingGOARCH
stands for Go Archetecture-o
only allowed when compiling a single package, define the name of output file
$ scp -i /path/to/[your].pem [binary-name] ubuntu@[public-DNS]:/home/ubuntu/[binary-name]
scp
stands for secure copy-i
stands for identity:
for root folder or:/home/ubuntu/[binary-name]
for more complex routes
$ ssh -i /path/to/[your].pem ubuntu@[public-DNS]
$ sudo chmod 700 [name-of-binary-file]
$ sudo nano /etc/systemd/system/[filename].service
as following
[Unit]
Description=Go Server
[Service]
ExecStart=/home/<username>/<path-to-exe>/<exe>
WorkingDirectory=/home/<username>/<exe-working-dir>
User=root
Restart=always
[Install]
WantedBy=multi-user.target
- Add the service to systemd.
sudo systemctl enable [filename].service
- Activate the service.
sudo systemctl start [filename].service
- Check if systemd started it.
sudo systemctl status [filename].service
- Stop systemd if so desired.
sudo systemctl stop [filename].service