In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to carry out the actual combat analysis of Serverless + CVM, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Project background
At present, there are customers who want to shut down a large number of test environments through non-working hours. At the same time, Tencent provides CVM operation with no charge for shutdown, which can save IT expenses to a certain extent, and start up in advance during working hours every morning, so it is obviously not appropriate to manually operate repeated periodic operations, but Common Cloud currently does not provide this product feature for server timing switch-off operation. You can only use its API, but you need a server with public network capability to initiate an API call request. This is a good time to take advantage of Serverless's Tencent Serverless Toolkit for VS Code trial. This example uses a small part of the features of Serverless in the simple example of Tencent Cloud function (SCF).
In the past, because there was no IDE, it was inconvenient to run and debug after deploying the program to SCF, but now we have the artifact Tencent Serverless Toolkit for VS Code, simple and convenient local configuration, quickly pull cloud functions and can locally simulate COS,CMQ,API gateway and other starting events to run and return the book. Localized development and debugging can be said to make up for the disadvantage that SCF is not convenient for code upload and debugging. Using this plug-in, you can quickly debug the code locally and upload the program with one click. Add wings to SCF.
Project preparation 1. Create a project based on a template
two。 Fill in the project name
Complete the project creation by filling in the project name
3. Understand the project structure
In the project template, we mainly focus on index.py and template.yaml
Index.py is the business logic code
Template.yaml is related to the configuration of Tencent Cloud SCF. The following is the configuration for my scheduled tasks.
To improve security, because Tencent Cloud secretid/secretkey is used, it is placed as a variable in the configuration, and the business code is obtained from the configuration.
The timeout and timing cron are also configured.
Resources: default: Type: TencentCloud::Serverless::Namespace cvm_oper: Properties: CodeUri:. Description: cvm oper Environment: Variables: secretid: AKIDZyGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx secretkey: kFUTDkxxxxxxxxxxxxxxxxxxxxxxxx Events: stop_cvm: Properties: CronExpression: 059 11 * * MON-FRI * Enable: true Type: Timer Handler: index.main_handler MemorySize: 128 Runtime: Python3.6 Timeout : 10 VpcConfig: SubnetId:''VpcId:' 'Type: TencentCloud::Serverless::Function write code 1. Code program
Here, I use the SDK of Tencent Cloud CVM to stop and boot the CVM. In this simple example, cvm starts.
Among them is event, for which the formal environment can pass in parameters of its own business requirements to handle specific business logic.
two。 Local testing
Run the test on the local IDE
Check and run successfully, and the server starts normally.
Upload project to cloud 1. Upload to the cloud for testing 2. Cloud View Project Cloud Test View run Log
So far, we have completed a simple project writing and deployment using Tencent Serverless Toolkit for VS Cod. Here, we just throw a brick to attract jade, and the actual code needs to take into account the incoming parameters, multi-project coordinated deployment and so on.
The above content is how to carry out the actual combat analysis of Serverless + CVM. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.