Template name
ACS-FC-RunScript
Template description
Executes a script in Python. To use this feature, you must quickly create a function.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
Runtime | The runtime environment. | String | No | python3.10 | |
Script | The Python script code. | String | No |
| |
FCAssumeRole | The RAM role that is assumed by Function Compute. | String | No | "" | |
OOSAssumeRole | The RAM role that is assumed by CloudOps Orchestration Service (OOS). | String | No | "" |
Output parameters
Parameter | Description | Type |
ScriptOutput | String |
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ros:CreateStack",
"ros:DeleteStack",
"ros:GetStack"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-FC-RunScript.yml at GitHub.
Template content
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>
name-en: ACS-FC-RunScript
Parameters:
Runtime:
Type: String
Label:
en: Runtime
AllowedValues:
- python3.9
- python3.10
Default: python3.10
Script:
Type: String
Label:
en: Python Script
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
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>
Type: String
AssociationProperty: ALIYUN::RAM::Service::Role
AssociationPropertyMetadata:
Service: fc.aliyuncs.com
Default: ''
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: ExecuteScript
Action: ACS::FC::ExecuteScript
Description:
en: Run the python script
Properties:
runtime: '{{ Runtime }}'
script: '{{ Script }}'
role: '{{ FCAssumeRole }}'
Outputs:
Result:
Type: String
ValueSelector: Result
Outputs:
ScriptOutput:
Type: String
Value: '{{ ExecuteScript.Result }}'