Updated on 2024-05-28 GMT+08:00

Building a Program

Download the graceful shutdown program package as_graceful_shutdown.zip and create a function from scratch.

Creating a Function

  1. Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
  2. Click Create Function.
  3. Click Create from scratch and configure the function information. After setting the basic information, click Create Function.
    • Function Type: Select Event Function.
    • Function Name: Enter as_graceful_shutdown.
    • Agency: Select ASOperation created in Creating an Agency.
    • Runtime: Select Python 3.6.
  4. On the Code tab of the as_graceful_shutdown function details page, choose Upload > Local ZIP, upload the sample code as_graceful_shutdown.zip. Choose Configuration > Basic Settings, set the following parameters, and click Save.
    • Memory: Select 128.
    • Execution Timeout: Enter 10.
    • Handler: Retain the default value index.handler.
    • App: Retain the default value default.
    • Description: Enter Graceful shutdown with AS.

Setting Environment Variables

On the details page of function as_graceful_shutdown, choose Configuration > Environment Variables, set environment variables according to Table 1, and click Save.

Table 1 Environment variable description

Environment Variable

Description

region

Region of your AS group.

projectId

Project ID of your AS group.

ak

Access key ID, which is a unique identifier used in conjunction with a secret access key to sign requests cryptographically. For details about how to obtain an AK, see Obtaining an AK/SK.

sk

Secret access key used together with an AK to sign requests cryptographically. It identifies a request sender and prevents the request from being modified. For details about how to obtain an SK, see Obtaining an AK/SK.

Adding Dependencies

  1. Create dependencies huaweicloudsdk_ecs_core_py3.6 and huaweicloudsdk_as_core_py3.6. For more information, see Creating a Dependency.

    You can also download the dependencies provided by FunctionGraph if needed:

  2. Return to the FunctionGraph console, and choose Functions > Dependencies in the navigation pane. Click Create Dependency, and create dependencies huaweicloudsdk_ecs_core_py3.6 and huaweicloudsdk_as_core_py3.6 successively.
  3. Set the dependency information and click OK.
    • Name: Enter huaweicloudsdk_ecs_core_py3.6 or huaweicloudsdk_as_core_py3.6.
    • Code Entry Mode: Select Upload ZIP.
    • Upload File: Select the target ZIP file.
    • Runtime: Select Python 3.6.
      Figure 1 Creating a dependency
  4. Go to the details page of function as_graceful_shutdown, click the Code tab, and click Add in the Dependencies area at the bottom.
  5. Add dependencies huaweicloudsdk_ecs_core_py3.6 and huaweicloudsdk_as_core_py3.6.