After you create a time trigger, you can start to define a function. This topic describes how to define a
function in the Function Compute console and trigger the function at a specified time.
Define a function by using Python
- Log on to the Function Compute console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Service/Function.
- Find the required function in the required service and click the name of the function.
- Click the Code tab and write code in the code editor.
In the following example, Python is used to define the function.
import json
import logging
logger = logging.getLogger()
def handler(event, context):
logger.info('event: %s', event)
evt = json.loads(event)
triggerName = evt["triggerName"]
triggerTime = evt["triggerTime"]
message = evt["payload"]
creds = context.credentials
logger.info('access_key_id: %s', creds.access_key_id)
logger.info("message = %s", message)
Event format
A time trigger triggers a function by parsing the following event format:
{
"triggerTime":"2018-02-09T05:49:00Z",
"triggerName":"my_trigger",
"payload":"awesome-fc"
}
Parameter |
Description |
triggerTime |
The triggering time of the function. |
triggerName |
The name of the time trigger. |
payload |
The input parameters defined in the settings of the trigger. |
What to do next
Debug a function