/
ACS::FC::ExecuteScript.json
168 lines (168 loc) · 5.64 KB
/
ACS::FC::ExecuteScript.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::FC::ExecuteScript",
"name-zh-cn": "执行python脚本(FC)",
"en": "Execute python script",
"zh-cn": "执行python脚本"
},
"Parameters": {
"runtime": {
"Type": "String",
"Label": {
"en": "Runtime",
"zh-cn": "函数的运行环境"
},
"AllowedValues": [
"python3.9",
"python3.10"
],
"Default": "python3.10"
},
"handler": {
"Type": "String",
"Label": {
"en": "Handler",
"zh-cn": "函数名称"
},
"Description": {
"en": "Python script function name(example:index.handler, index is the file name, handler is the name of the script function.)",
"zh-cn": "python脚本函数名称(例:index.handler, index是文件名,handler是脚本函数名)"
},
"Default": "index.handler"
},
"inputPayload": {
"Type": "Json",
"Label": {
"en": "InputPayload",
"zh-cn": "输入参数"
},
"Description": {
"en": "The parameter value of the script",
"zh-cn": "脚本的参数值"
},
"Default": ""
},
"script": {
"Type": "String",
"Label": {
"en": "Python Script",
"zh-cn": "python脚本代码"
},
"AssociationProperty": "ALIYUN::OOS::Command::CommandContent",
"AssociationPropertyMetadata": {
"CommandType": "RunPythonScript"
},
"Default": "import datetime\nimport os\nimport sys\n\ndef _now(format=\"%Y-%m-%d %H:%M:%S\"):\n return datetime.datetime.now().strftime(format)\n\ndef job_start():\n return (\"[%s][%s] job_start\" % (_now(), os.getpid()))\n\ndef handler(event, context):\n return job_start()"
},
"role": {
"Type": "String",
"Label": {
"en": "RamRoleArn",
"zh-cn": "授予函数计算所需权限的RAM角色ARN"
},
"Description": {
"en": "Format:\"acs:ram::{{ACS::AccountId}}:role/{RoleName}, for example:\"acs:ram::{{ACS::AccountId}}:role/fc-test-role\"",
"zh-cn": "格式:\"acs:ram::{{ACS::AccountId}}:role/{RoleName}, 如:\"acs:ram::{{ACS::AccountId}}:role/fc-test-role\""
},
"Default": ""
}
},
"Tasks": [
{
"Name": "createStack",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Creates a resource stack",
"zh-cn": "创建资源栈"
},
"Properties": {
"Service": "ROS",
"API": "CreateStack",
"Parameters": {
"StackName": {
"Fn::Replace": [
{
".": "_"
},
"OOS-{{ACS::ExecutionId}}"
]
},
"TimeoutInMinutes": 10,
"DisableRollback": false,
"Parameters": [
{
"ParameterKey": "ParameterKeys",
"ParameterValue": "{{ inputPayload }}"
},
{
"ParameterKey": "Script",
"ParameterValue": "{{ script }}"
}
],
"TemplateBody": "ROSTemplateFormatVersion: 2015-09-01\nParameters:\n ParameterKeys:\n Type: String\n Script:\n Type: String\nResources:\n Service:\n Type: ALIYUN::FC::Service\n Properties:\n ServiceName:\n Ref: ALIYUN::StackName\n Role: \"{{ role }}\"\n Function:\n Type: ALIYUN::FC::Function\n DependsOn: Service\n Properties:\n ServiceName:\n Ref: ALIYUN::StackName\n FunctionName:\n Ref: ALIYUN::StackName\n Code:\n SourceCode: \n Ref: Script\n Handler: \"{{ handler }}\"\n Runtime: \"{{ runtime }}\"\n Timeout: 300\n FunctionInvoker:\n Type: ALIYUN::FC::FunctionInvoker\n DependsOn: Function\n Properties:\n ServiceName:\n Ref: ALIYUN::StackName\n FunctionName:\n Ref: ALIYUN::StackName\n Async: false\n Event:\n Ref: ParameterKeys\n ExecuteVersion: 0\nOutputs:\n Result:\n Value:\n Fn::Replace:\n - FcResult:\n Fn::GetAtt:\n - FunctionInvoker\n - Result\n - FcResult\nMetadata:\n ALIYUN::ROS::Interface:\n TemplateTags:\n - acs:integrate:oos:fc_execute_script"
}
},
"Outputs": {
"stackId": {
"Type": "String",
"ValueSelector": "StackId"
}
}
},
{
"Name": "untilStackReady",
"Action": "ACS::WaitFor",
"OnError": "deleteStack",
"Description": {
"en": "Waits for the stack status util CREATE_COMPLETE",
"zh-cn": "等待资源栈状态至CREATE_COMPLETE"
},
"Properties": {
"Service": "ROS",
"API": "GetStack",
"Parameters": {
"StackId": "{{createStack.stackId}}"
},
"DesiredValues": [
"CREATE_COMPLETE"
],
"StopRetryValues": [
"CREATE_FAILED",
"CHECK_FAILED",
"ROLLBACK_FAILED",
"ROLLBACK_COMPLETE",
"CREATE_ROLLBACK_COMPLETE"
],
"PropertySelector": "Status"
},
"Outputs": {
"result": {
"Type": "String",
"ValueSelector": "Outputs[].OutputValue"
}
}
},
{
"Name": "deleteStack",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Deletes the stack",
"zh-cn": "删除资源栈"
},
"Properties": {
"Service": "ROS",
"API": "DeleteStack",
"Parameters": {
"StackId": "{{createStack.stackId}}"
}
}
}
],
"Outputs": {
"Result": {
"Type": "String",
"Value": "{{ untilStackReady.result }}"
}
}
}