huawei-cloud-functiongraph-function-create

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

FunctionGraph Function Creation Skill

FunctionGraph函数创建技能

Overview

概述

This skill creates FunctionGraph functions on Huawei Cloud based on user-provided parameters including function name, runtime, and code content.
Architecture: Uses Huawei Cloud FunctionGraph Python SDK to interact with FunctionGraph service.
Applicable Scenarios:
  • Quickly create cloud functions without manual console login
  • Batch creation of multiple functions
  • Foundation component for workflow deployment
  • CI/CD integration for function deployment
Typical Use Cases:
  1. "Create a Python function named my_handler"
  2. "Deploy this code to FunctionGraph"
  3. "Batch create 10 functions from template"
本技能可根据用户提供的参数(包括函数名称、runtime和代码内容)在华为云创建FunctionGraph函数。
架构:使用华为云FunctionGraph Python SDK与FunctionGraph服务进行交互。
适用场景:
  • 无需手动登录控制台即可快速创建云函数
  • 批量创建多个函数
  • 工作流部署的基础组件
  • 集成CI/CD进行函数部署
典型用例:
  1. "创建一个名为my_handler的Python函数"
  2. "将此代码部署到FunctionGraph"
  3. "从模板批量创建10个函数"

Prerequisites

前提条件

1. Python Environment

1. Python环境

  • Python 3.9+
  • Verify:
    python --version
  • Python 3.9+
  • 验证命令:
    python --version

2. SDK Installation

2. SDK安装

bash
pip install huaweicloudsdkfunctiongraph
bash
pip install huaweicloudsdkfunctiongraph

3. Authentication Configuration

3. 认证配置

  • Valid Huawei Cloud credentials (AK/SK mode)
  • Configure via environment variables:
bash
export HUAWEI_AK="your-access-key"
export HUAWEI_SK="your-secret-key"
export HUAWEI_REGION="cn-north-4"
export HUAWEI_PROJECT_ID="your-project-id"
Security Rules:
  • NEVER expose AK/SK values in code or logs
  • NEVER let users input AK/SK directly in conversation
  • ALWAYS use environment variables for credentials
  • Recommend using IAM user instead of main account
  • 有效的华为云凭证(AK/SK模式)
  • 通过环境变量配置:
bash
export HUAWEI_AK="your-access-key"
export HUAWEI_SK="your-secret-key"
export HUAWEI_REGION="cn-north-4"
export HUAWEI_PROJECT_ID="your-project-id"
安全规则:
  • 绝对不要在代码或日志中暴露AK/SK值
  • 绝对不要让用户在对话中直接输入AK/SK
  • 始终使用环境变量存储凭证
  • 推荐使用IAM用户而非主账号

4. IAM Permission Requirements

4. IAM权限要求

  • functiongraph:function:create
    - Create function
  • functiongraph:function:get
    - Query function details
  • functiongraph:function:list
    - List functions
See IAM Policies for detailed permission configuration.
  • functiongraph:function:create
    - 创建函数
  • functiongraph:function:get
    - 查询函数详情
  • functiongraph:function:list
    - 列出函数
详细权限配置请参考IAM策略

Usage

使用方法

Command

命令

bash
cd scripts
python create_function.py   --name <function_name>   --runtime <runtime>   --han
dler <handler>   --code <code_content>   --memory <memory_size>   --timeout <timeout>
bash
cd scripts
python create_function.py   --name <function_name>   --runtime <runtime>   --handler <handler>   --code <code_content>   --memory <memory_size>   --timeout <timeout>

Parameter Confirmation

参数确认

|| Parameter | Required/Optional | Description | Default || || ----------- | ------------------ | ------------- | --------- || ||
function_name
| Required | Function name, must follow naming rules | - || ||
runtime
| Required | Runtime environment (Python3.9, etc.) | - || ||
code_content
| Required | Function code content | - || ||
handler
| Required | Function entry point (e.g., index.handler) | - || ||
memory_size
| Optional | Memory size in MB | 128 || ||
timeout
| Optional | Timeout in seconds | 3 || ||
description
| Optional | Function description | - ||
|| 参数 | 必填/可选 | 描述 | 默认值 || || ----------- | ------------------ | ------------- | --------- || ||
function_name
| 必填 | 函数名称,必须符合命名规则 | - || ||
runtime
| 必填 | 运行时环境(如Python3.9等) | - || ||
code_content
| 必填 | 函数代码内容 | - || ||
handler
| 必填 | 函数入口(例如:index.handler) | - || ||
memory_size
| 可选 | 内存大小(MB) | 128 || ||
timeout
| 可选 | 超时时间(秒) | 3 || ||
description
| 可选 | 函数描述 | - ||

Runtime Options

运行时选项

|| Runtime | Handler Format | Example || || --------- | ---------------- | --------- || || Python3.9 | index.handler |
def handler(event, context):
|| || Node.js14.18 | index.handler |
exports.handler = (event, context) => {}
|| || Java8 | com.example.Handler::handleRequest | Java class method || || Go1.x | handler | Go function name ||
|| 运行时 | Handler格式 | 示例 || || --------- | ---------------- | --------- || || Python3.9 | index.handler |
def handler(event, context):
|| || Node.js14.18 | index.handler |
exports.handler = (event, context) => {}
|| || Java8 | com.example.Handler::handleRequest | Java类方法 || || Go1.x | handler | Go函数名称 ||

Verification Method

验证方法

See Verification Method for detailed procedures.
详细步骤请参考验证方法

Quick Verification

快速验证

python
undefined
python
undefined

Verify function exists using SDK

使用SDK验证函数是否存在

from huaweicloudsdkfunctiongraph.v2.functiongraph_client import FunctionGraphClient from huaweicloudsdkfunctiongraph.v2.model import ListFunctionsRequest
from huaweicloudsdkfunctiongraph.v2.functiongraph_client import FunctionGraphClient from huaweicloudsdkfunctiongraph.v2.model import ListFunctionsRequest

List functions to verify creation

列出函数以验证创建结果

client = FunctionGraphClient.new_builder().build() request = ListFunctionsRequest() response = client.list_functions(request) print(f"Total functions: {len(response.functions)}")
undefined
client = FunctionGraphClient.new_builder().build() request = ListFunctionsRequest() response = client.list_functions(request) print(f"Total functions: {len(response.functions)}")
undefined

Output Format

输出格式

The skill returns a structured JSON object with the following fields:
  • function_urn
    : Unique resource identifier of the created function
  • function_name
    : Name of the created function
  • runtime
    : Runtime environment
  • memory_size
    : Allocated memory in MB
  • timeout
    : Function timeout in seconds
  • handler
    : Function entry point
  • description
    : Function description (if provided)
Example output:
json
{
  "function_urn": "urn:fss:cn-north-4:project_id:function:default:my_function",
  "function_name": "my_function",
  "runtime": "Python3.9",
  "memory_size": 128,
  "timeout": 3,
  "handler": "index.handler",
  "description": "Test function created by skill"
}
本技能返回一个结构化的JSON对象,包含以下字段:
  • function_urn
    : 创建的函数的唯一资源标识符
  • function_name
    : 创建的函数名称
  • runtime
    : 运行时环境
  • memory_size
    : 分配的内存大小(MB)
  • timeout
    : 函数超时时间(秒)
  • handler
    : 函数入口
  • description
    : 函数描述(若提供)
示例输出:
json
{
  "function_urn": "urn:fss:cn-north-4:project_id:function:default:my_function",
  "function_name": "my_function",
  "runtime": "Python3.9",
  "memory_size": 128,
  "timeout": 3,
  "handler": "index.handler",
  "description": "Test function created by skill"
}

Best Practices

最佳实践

  1. Test before production: Always test in a development environment first
  2. Monitor resources: Set up monitoring for function invocations and errors
  3. Use environment variables: Store sensitive data in environment variables
  4. Implement error handling: Add proper error handling in function code
  5. Set appropriate timeouts: Configure timeout based on function logic
  1. 生产前测试:始终先在开发环境中进行测试
  2. 监控资源:设置函数调用和错误的监控
  3. 使用环境变量:将敏感数据存储在环境变量中
  4. 实现错误处理:在函数代码中添加适当的错误处理
  5. 设置合适的超时时间:根据函数逻辑配置超时时间

Error Handling

错误处理

|| Error Code | Description | Resolution || || ------------ | ------------- | ------------ || || InvalidParameter | Invalid input parameters | Check parameter format and valu es || || InsufficientPermission | Insufficient permissions | Check IAM permissions || || QuotaExceeded | Resource quota exceeded | Request quota increase or delete un used functions || || FunctionAlreadyExists | Function with same name exists | Use different functi on name or delete existing function ||
|| 错误码 | 描述 | 解决方法 || || ------------ | ------------- | ------------ || || InvalidParameter | 输入参数无效 | 检查参数格式和值 || || InsufficientPermission | 权限不足 | 检查IAM权限 || || QuotaExceeded | 资源配额超出 | 申请配额提升或删除未使用的函数 || || FunctionAlreadyExists | 同名函数已存在 | 使用不同的函数名称或删除现有函数 ||

References

参考资料