模板名稱
ACS-FC-RunScript FC運行指令碼
模板描述
FC運行指令碼(僅支援python),使用此功能必須快速建立函數
模板類型
自動化
所有者
Alibaba Cloud
輸入參數
參數名稱 | 描述 | 類型 | 是否必填 | 預設值 | 約束 |
Runtime | 運行環境 | String | 否 | python3.10 | |
Script | python指令碼代碼 | String | 否 |
| |
FCAssumeRole | FC扮演的RAM角色 | String | 否 | "" | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | "" |
輸出參數
參數名稱 | 描述 | 類型 |
ScriptOutput | String |
執行此模板需要的權限原則
{
"Version": "1",
"Statement": [
{
"Action": [
"ros:CreateStack",
"ros:DeleteStack",
"ros:GetStack"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳情
模板內容
FormatVersion: OOS-2019-06-01
Description:
en: FC runs script(Only support python), To use this template, you must first <a href='https://help.aliyun.com/zh/functioncompute/getting-started/quickly-create-a-function#p-t79-y7o-68z' target="_blank">activate the function computing service< /a>
zh-cn: FC運行指令碼(僅支援python),使用此功能必須<a href='https://help.aliyun.com/zh/functioncompute/getting-started/quickly-create-a-function#p-t79-y7o-68z' target="_blank">開通Function Compute服務</a>
name-en: ACS-FC-RunScript
name-zh-cn: FC運行指令碼
Parameters:
Runtime:
Type: String
Label:
en: Runtime
zh-cn: 運行環境
AllowedValues:
- python3.9
- python3.10
Default: python3.10
Script:
Type: String
Label:
en: Python Script
zh-cn: python指令碼代碼
AssociationProperty: ALIYUN::OOS::Command::CommandContent
AssociationPropertyMetadata:
CommandType: RunPythonScript
Default: |-
import datetime
import os
import sys
def _now(format="%Y-%m-%d %H:%M:%S"):
return datetime.datetime.now().strftime(format)
def job_start():
return ("[%s][%s] job_start" % (_now(), os.getpid()))
def handler(event, context):
return job_start()
FCAssumeRole:
Label:
en: FCAssumeRole
zh-cn: FC扮演的RAM角色
Description:
en: The Function Compute platform will use this RAM role to generate a temporary key for accessing your Alibaba Cloud resources and pass it to your code. For details, please see <a href="https://help.aliyun.com/zh/functioncompute/user-guide/grant-function-compute-permissions-to-access-other-alibaba-cloud-services" target="_blank ">Grant Function Compute permissions to access other cloud services</a>
zh-cn: Function Compute平台會使用這個 RAM 角色(Role)來產生訪問您的阿里雲資源的臨時密鑰,並傳遞給您的代碼。詳情請查看<a href="https://help.aliyun.com/zh/functioncompute/user-guide/grant-function-compute-permissions-to-access-other-alibaba-cloud-services" target="_blank">授予Function Compute訪問其他雲端服務的許可權</a>
Type: String
AssociationProperty: ALIYUN::RAM::Service::Role
AssociationPropertyMetadata:
Service: fc.aliyuncs.com
Default: ''
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: ExecuteScript
Action: ACS::FC::ExecuteScript
Description:
en: Run the python script
zh-cn: 運行Python指令碼
Properties:
runtime: '{{ Runtime }}'
script: '{{ Script }}'
role: '{{ FCAssumeRole }}'
Outputs:
Result:
Type: String
ValueSelector: Result
Outputs:
ScriptOutput:
Type: String
Value: '{{ ExecuteScript.Result }}'