-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathACS::FC::ExecuteScript.json
More file actions
172 lines (172 loc) · 6.23 KB
/
ACS::FC::ExecuteScript.json
File metadata and controls
172 lines (172 loc) · 6.23 KB
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
169
170
171
172
{
"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"
},
"script": {
"Type": "String",
"Label": {
"en": "Python Script",
"zh-cn": "Python脚本代码"
},
"AssociationProperty": "ALIYUN::OOS::Command::CommandContent",
"AssociationPropertyMetadata": {
"CommandType": "RunPythonScript"
},
"Default": "import json\n\ndef handler(event, context):\n # 解析传入的调用参数\n data = json.loads(event)\n handler_name = data.get('handler_name')\n print(f'My name is {handler_name}')\n return handler_name"
},
"inputPayload": {
"Type": "String",
"Label": {
"en": "The parameters of function invocation",
"zh-cn": "函数调用参数"
},
"Description": {
"en": "JSON Format: {\"key\": \"value\"} Please refer to <a href=\"https://www.alibabacloud.com/help/en/functioncompute/user-guide/event-handlers#section-qv4-7ev-s0q\" target=\"_blank\">document</a>",
"zh-cn": "JSON格式:{\"key\": \"value\"} 详情请<a href=\"https://help.aliyun.com/zh/functioncompute/user-guide/event-handlers#section-qv4-7ev-s0q\" target=\"_blank\">参考</a>"
},
"Default": "{\"handler_name\": \"fc_demo\"}"
},
"role": {
"Type": "String",
"Label": {
"en": "FCRamRole",
"zh-cn": "授予函数计算所需权限的RAM角色"
},
"AssociationProperty": "ALIYUN::RAM::Service::Role",
"AssociationPropertyMetadata": {
"Service": "fc.aliyuncs.com"
},
"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 }}"
},
{
"ParameterKey": "Role",
"ParameterValue": "{{ role }}"
}
],
"TemplateBody": "ROSTemplateFormatVersion: 2015-09-01\nParameters:\n ParameterKeys:\n Type: String\n Script:\n Type: String\n Role:\n Type: String\n Default: ''\nConditions:\n Role:\n Fn::Equals:\n - Ref: Role\n - ''\nResources:\n Service:\n Type: ALIYUN::FC::Service\n Properties:\n ServiceName:\n Ref: ALIYUN::StackName\n Role: \n Fn::If:\n - Role\n - ''\n - Fn::Sub:\n - acs:ram::${AccountId}:role/${Role}\n - AccountId: '{{ ACS::AccountId }}'\n Role:\n Ref: 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 }}"
}
}
}