huawei-cloud-functiongraph-function-create
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFunctionGraph 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:
- "Create a Python function named my_handler"
- "Deploy this code to FunctionGraph"
- "Batch create 10 functions from template"
本技能可根据用户提供的参数(包括函数名称、runtime和代码内容)在华为云创建FunctionGraph函数。
架构:使用华为云FunctionGraph Python SDK与FunctionGraph服务进行交互。
适用场景:
- 无需手动登录控制台即可快速创建云函数
- 批量创建多个函数
- 工作流部署的基础组件
- 集成CI/CD进行函数部署
典型用例:
- "创建一个名为my_handler的Python函数"
- "将此代码部署到FunctionGraph"
- "从模板批量创建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 huaweicloudsdkfunctiongraphbash
pip install huaweicloudsdkfunctiongraph3. 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权限要求
- - Create function
functiongraph:function:create - - Query function details
functiongraph:function:get - - List functions
functiongraph:function:list
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 ||
|| ----------- | ------------------ | ------------- | --------- ||
|| | Required | Function name, must follow naming rules | - ||
|| | Required | Runtime environment (Python3.9, etc.) | - ||
|| | Required | Function code content | - ||
|| | Required | Function entry point (e.g., index.handler) | - ||
|| | Optional | Memory size in MB | 128 ||
|| | Optional | Timeout in seconds | 3 ||
|| | Optional | Function description | - ||
function_nameruntimecode_contenthandlermemory_sizetimeoutdescription|| 参数 | 必填/可选 | 描述 | 默认值 ||
|| ----------- | ------------------ | ------------- | --------- ||
|| | 必填 | 函数名称,必须符合命名规则 | - ||
|| | 必填 | 运行时环境(如Python3.9等) | - ||
|| | 必填 | 函数代码内容 | - ||
|| | 必填 | 函数入口(例如:index.handler) | - ||
|| | 可选 | 内存大小(MB) | 128 ||
|| | 可选 | 超时时间(秒) | 3 ||
|| | 可选 | 函数描述 | - ||
function_nameruntimecode_contenthandlermemory_sizetimeoutdescriptionRuntime Options
运行时选项
|| Runtime | Handler Format | Example ||
|| --------- | ---------------- | --------- ||
|| Python3.9 | index.handler | ||
|| Node.js14.18 | index.handler | ||
|| Java8 | com.example.Handler::handleRequest | Java class method ||
|| Go1.x | handler | Go function name ||
def handler(event, context):exports.handler = (event, context) => {}|| 运行时 | Handler格式 | 示例 ||
|| --------- | ---------------- | --------- ||
|| Python3.9 | index.handler | ||
|| Node.js14.18 | index.handler | ||
|| Java8 | com.example.Handler::handleRequest | Java类方法 ||
|| Go1.x | handler | Go函数名称 ||
def handler(event, context):exports.handler = (event, context) => {}Verification Method
验证方法
See Verification Method for detailed
procedures.
详细步骤请参考验证方法。
Quick Verification
快速验证
python
undefinedpython
undefinedVerify 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)}")
undefinedclient = FunctionGraphClient.new_builder().build()
request = ListFunctionsRequest()
response = client.list_functions(request)
print(f"Total functions: {len(response.functions)}")
undefinedOutput Format
输出格式
The skill returns a structured JSON object with the following fields:
- : Unique resource identifier of the created function
function_urn - : Name of the created function
function_name - : Runtime environment
runtime - : Allocated memory in MB
memory_size - : Function timeout in seconds
timeout - : Function entry point
handler - : Function description (if provided)
description
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 - : 分配的内存大小(MB)
memory_size - : 函数超时时间(秒)
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
最佳实践
- Test before production: Always test in a development environment first
- Monitor resources: Set up monitoring for function invocations and errors
- Use environment variables: Store sensitive data in environment variables
- Implement error handling: Add proper error handling in function code
- Set appropriate timeouts: Configure timeout based on function logic
- 生产前测试:始终先在开发环境中进行测试
- 监控资源:设置函数调用和错误的监控
- 使用环境变量:将敏感数据存储在环境变量中
- 实现错误处理:在函数代码中添加适当的错误处理
- 设置合适的超时时间:根据函数逻辑配置超时时间
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
参考资料
- FunctionGraph Documentation
- Python SDK Documentation
- IAM Policies Guide
- Verification Method
- FunctionGraph文档
- Python SDK文档
- IAM策略指南
- 验证方法