Startups: Why should I migrate SpringBoot to Alibaba Cloud Function Compute?

foreword

Why migrate? Our business has many RESTful APIs that provide external services and perform many different tasks, such as synchronizing commodity information in chain ERP to platforms such as Meituan/Ele.me, and online invoicing. Due to the uncertainty of various APIs and task execution, services are often unavailable due to insufficient resources, but blind expansion is costly. The entire team is stuck in constant expansion and contraction every day .

The key is that sometimes it is a little slower, which will affect the business and lead to complaints. Every day, they are urged by other business departments to make new functions. What is even more difficult is that because we have no experience in operation and maintenance, we have been repeatedly used by hackers for mining with our few machines. As a R&D team of a start-up company, we have few resources, less manpower and less experience. It is really painful to face the pressure of stability, security and business.

After being introduced to Alibaba Cloud Function Compute FC by my former colleague Amway, I found it very useful! The migration process was very smooth, and the effect of the migration greatly exceeded my expectations. Here are the reasons why I think Alibaba Cloud Function Compute FC is very suitable for us:

  • **Default elasticity:** It can easily handle a large number of API requests and tasks, and will no longer be unavailable due to resource exhaustion due to untimely expansion!
  • **Support downscaling to 0 when there is no traffic: **A money-saving artifact, no need to buy virtual machines and load balancing anymore, for us, the cost reduction effect is great!
  • **Free operation and maintenance: **The operation and maintenance cost of the virtual machine is eliminated!
  • ** MORE SAFE: ** It can't be SSHed into, and it won't stay on like a virtual machine, waiting to be scanned and hacked!
  • **Zero modification:** No need to modify the code, the JAR package on the previous virtual machine can directly run on Alibaba Cloud Function Compute FC!

Migration steps

There are three ways to use it, here I will talk about how to operate on the console.

1. Use the Alibaba Cloud Function Compute FC console to migrate.

2. Use the S tool provided by Alibaba Cloud Function Compute FC to deploy through the command line + YAML. For details, please refer to the end of the article [1].

3. Use the application center on the Alibaba Cloud Function Compute FC console to automatically build and deploy from source code repositories such as GitHub. CICD/GitOps is there directly, it's so fragrant! Details can be found at the end of the text [2].

Open Function Compute

Access the console [3], click Free activation will jump to the activation page:

Create Service Click Service and Function to create a service, enter the "name" and click OK:

Compress the JAR package to get a ZIP file

Notice! Here we need to compress the packaged JAR package, and then upload the ZIP package! ! !

Note: In fact, you can also upload the JAR package directly; but the startup command should be written as: java org.springframework.boot.loader.JarLauncher I personally don't like this way of writing, but I still like: java -jar gs-rest-service-0.1 .0.jar

If you don't have a JAR package available, please refer to the SpringBoot official quick start documentation [4] to build it.

create function

  • On the Function Management page, click Create Function
  • Option to use custom runtime for smooth migration of Web Server
  • Run Environment Select the Java version you need
  • Option to upload code via ZIP package
  • The startup command is your command to start the JAR package on the virtual machine, for example: java -jar rest-service-initial-0.0.1-SNAPSHOT.jar.zip
  • The listening port is the port that your JAVA program is listening on on the virtual machine, for example: 8080
  • The request handler type chooses to handle HTTP requests
  • Click to create

test function

Find "Public Network Access Address" in the trigger list on the function details page. Note: Due to relevant regulations, this URL cannot be opened directly in the browser, and you need to configure your own domain name to access it in the browser.

You can test with curl command. You can also test directly through the Test Functions tab in the function details page.

Use your own domain name to access functions

  • Click Home, Domain Name Management, Create Domain Name, Add Custom Domain Name
  • Copy the "public network CNAME" on the page, and add a CNAME record for your domain name on the DNS console [5]
  • Select the service and function you just created in the routing configuration
  • Click to create
  • Finish! The service can now be accessed through your own domain name!

image.png

After the migration

In the face of traffic peaks, we will no longer be in a hurry, and Alibaba Cloud Function Compute FC will automatically help us expand! It's a good solution to our API scenarios and scenarios that perform various tasks from time to time. It is a great benefit for a small team like us who do not understand Docker, do not understand Kubernetes, and have no operation and maintenance personnel. It is difficult for us to expand and shrink virtual machines.

At the same time, we no longer have to buy virtual machines and load balancers! The method of scaling down to 0 and pay-as-you-go has also greatly reduced our costs! Also, we've never been hacked again and mined with our money! All in all, two words! So fragrant!

More advanced understanding [1] Details 1: https://github.com/devsapp/start-web-framework/tree/master/web-framework/java/springboot [2] Details 2: https://fcnext. console.aliyun.com/applications/create [3] Console: https://fcnext.console.aliyun.com/ [4] SpringBoot official quick start documentation: https://spring.io/guides/gs/rest- service/ [5] Cloud DNS console: https://dns.console.aliyun.com/ [6] Configure NAS file system: https://help.aliyun.com/document_detail/87401.html [7] Configure HTTPS: https://help.aliyun.com/document_detail/90763.html [8] Authorization function to access other services: https://help.aliyun.com/document_detail/181589.html [9] Access to resources in VPC: https://help.aliyun.com/document_detail/72959.html[10] Access RDS database: https://help.aliyun.com/document_detail/84514.html [11] Access Redis cache: https://help.aliyun.com/document_detail/148798.html [12] More quick Getting Started Documentation: https://fcnext.console.aliyun.com/overview

For more content, pay attention to the Serverless WeChat official account (ID: serverlessdevs), which brings together the most comprehensive content of serverless technology, regularly holds serverless events, live broadcasts, and user best practices.

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4611872/blog/5560920