Periodically Starting or Stopping HUAWEI CLOUD ECSs
Introduction
If you need to start or stop your ECSs at specified time, you can use FunctionGraph to call the corresponding ECS APIs.
Building a Program
- Create an agency named EcsOperation that delegates FunctionGraph to access other cloud services.
An agency is required if FunctionGraph accesses other cloud services. For details on how to create an agency, see Creating an Agency.
- Create a function.
Create a function for periodically starting or stopping ECSs. You need to upload the program package (for starting or stopping ECSs) as shown in Figure 1 and select the agency created in 1. For details, see Creating a Function.
- Set environment variables.
On the Configuration tab page, set environment variables according to Table 1.
Table 1 Environment variables Environment Variable
Description
region
Region where your ECSs are located, for example, cn-north-4.
domain
Endpoint of the ECS service in the format of "{region}.{domain}", for example, cn-north-4.myhuaweicloud.com. To obtain the endpoint information, see Regions and Endpoints.
projectId
ID of the project to which the ECSs belong.
whiteLists
- If you want to periodically start certain ECSs, specify the names of the ECSs that do not need to be started and separate them with commas (,).
- If you want to periodically stop certain ECSs, specify the names of the ECSs that do not need to be stopped and separate them with commas (,).
Set the environment variables (Figure 2) by following the procedure in Environment Variables.
- This practice does not have limitations on the region for function execution. For example, if your function runs in CN North-Beijing1 and you want to start or stop ECSs deployed in CN North-Beijing4, change the projectId, region, and domain parameters to those of the CN North-Beijing4 region.
- If a large number of ECSs need to be started or stopped, increase the execution timeout for your function.
- In Table 1, all environment variables except domain and whiteLists are mandatory. If you do not specify a domain, the default value myhuaweicloud.com of the domain parameter in the program package will be used. For whiteLists, specify the names of the ECSs to be started or stopped and separate them with commas (,).
- Add a dependency.
On the Code tab page, select the openstacksdk-1.0.6 dependency, as shown in Figure 3. To download the openstacksdk-1.0.6 dependency, visit HUAWEI CLOUD SDKs.
For more information, see Configuring Dependencies for a Function.
Adding an Event Source
Last Article: Processing Operation Records




Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.