How to deploy a Go application to an ECS instance

This time, I will show you how to deploy ** Go application ** on ** Alibaba Cloud ECS instance **.

In the previous article, I showed you how to deploy your local Java application directly to your Alibaba Cloud ECS instance. This time, I will show you how to deploy a Go application on an Alibaba Cloud Elastic Compute Service (ECS) instance.

Develop your application locally

Whether you compile a Go application that runs in the cloud or a Go application that runs locally, the coding method is the same. Therefore, in this article, we will explain how to deploy using a Go application that prints "Hello World" on a Web page as an example.

image.png

//Alibaba Cloud Toolkit. http://www.aliyun.com/product/cloudtoolkit
func setupRouter() *gin.Engine {
    // Disable Console Color
    // gin.DisableConsoleColor()
    r := gin.Default()
    // Ping test
    r.GET("/ping", func(c *gin.Context) {
        c.String(http.StatusOK, "Alibaba Cloud Toolkit: Hello World.")
    })
    return r
}
func main() {
    r := setupRouter()
    // Listen and Server in 0.0.0.0:8080
    r.Run(":80")
}

You can download the source code from this link.

The above code is a standard Go project used to display the string "Hello World" on a web page.

Plugin installation

Alibaba Cloud provides Eclipse-based plugins that allow developers to efficiently deploy applications written in their local IDE to ECS instances.

Plugin URL: https://www.aliyun.com/product/cloudtoolkit_en

The procedure for installing this Eclipse-based plug-in is similar to a typical plug-in, so we won't go into details here.

Plugin preferences

After installing the plugin, select it and configure the preferences.

Select Top Menu> Window> Preferences> Alibaba Cloud Toolkit> Account.

When the next page appears, set the AK and SK for your Alibaba Cloud account and you're done setting up your preferences (if you're using a RAM user account, enter the AK and SK for your RAM user) ).

image.png

Deploy application

image.png

Right-click on the project name in Eclipse and select Alibaba Cloud> Deploy to ECS from the shortcut menu. The following deployment screen will be displayed.

image.png

In the Placement Settings dialog box, set the placement parameters and click Placement to complete the initial placement.

Description of placement parameters

--Deployment file: There are two options. --Maven Build: If you are using Maven to build your current project, you can use Alibaba Cloud Toolkit to build and deploy your application directly. --File Upload: If you are not using Maven to build your current project, or if you already have a locally packaged deployment file, you can select your local deployment file and upload it directly. --Select ECS to deploy: Select a region from the drop-down list and select the ECS instance to deploy to that region. --Specify deployment destination: Enter the deployment path on the ECS instance. --Command: Enter the application startup command. This parameter specifies the command to be executed after the application package is deployed. For Go programs, you typically enter a series of program launch commands.

source ~/.bash_profile
pkill -f 'go-demo'
mv /tmp/go-demo /root/go-demo
chmod 755 /root/go-demo
sh -c /root/go-demo

Recommended Posts

How to deploy a Go application to an ECS instance
How to deploy a Streamlit application to GCP (GAE)
How to deploy a Django application on Alibaba Cloud
How to convert an array to a dictionary with Python [Application]
How to deploy a web application on Alibaba Cloud as a freelancer
[Go] How to write or call a function
[Go] How to create a custom error for Sentry
How to make an HTTPS server with Go / Gin
How to call a function
How to hack a terminal
[Go] How to use "... (3 periods)"
How to deploy a web app made with Flask to Heroku
How to generate a public key from an SSH private key
How to make a Python package (written for an intern)
How to check if a value exists in an enum
[Python] How to output a pandas table to an excel file
How to create an instance of a particular class from dict using __new__ () in python
How to make a Japanese-English translation
How to paste a CSV file into an Excel file using Pandas
How to write a Python class
How to put a symbolic link
A game to go on an adventure in python interactive mode
Deploy a Django application with Docker
How to make a slack bot
How to create a Conda package
How to create an email user
How to make a crawler --Advanced
How to deploy django-compressor on Windows
How to make a recursive function
How to create a virtual bridge
How to create a heatmap with an arbitrary domain in Python
How to pass arguments using an instance with systemd's systemctl command
How to make a deadman's switch
How to create a Dockerfile (basic)
[Blender] How to make a Blender plugin
Convert a string to an image
How to deploy a Django app on heroku in just 5 minutes
How to delete a Docker container
How to get a job as an engineer from your 30s
How to make a crawler --Basic
Building an environment to run ChainerMN on a GPU instance on AWS
How to install Go on Ubuntu
How to create a config file
How to make a request to bitFlyer Lightning's Private API in Go language
How to build an application from the cloud using the Django web framework
How to create a clone from Github
How to split and save a DataFrame
How to build a sphinx translation environment
How to create a git clone folder
Qiita (1) How to write a code name
How to add a package with PyCharm
[Python] How to make a class iterable
How to draw a graph using Matplotlib
[Python] How to convert a 2D list to a 1D list
How to create an NVIDIA Docker environment
How to convert Python to an exe file
[Colab] How to copy a huge dataset
[Python] How to invert a character string
How to install a package using a repository
Installing Anaconda Python on an ECS instance
[Ubuntu] How to execute a shell script