in solution/compliance/3.4-sub-resource-changes/python_script/subscription.py [0:0]
def createFunction(args: FCConfig, ) -> None:
client = Fc.createClient(args.ak, args.sk, args.sts, args.account)
create_function_headers = fc__open_20210406_models.CreateFunctionHeaders()
lifecycConfig = fc__open_20210406_models.InstanceLifecycleConfig(
pre_stop=fc__open_20210406_models.LifecycleHook(
handler="index.pre_stop",
),
)
code = fc__open_20210406_models.Code(
oss_bucket_name=args.code_oss_bucket_name,
oss_object_name=args.code_oss_object_name
)
create_function_request = fc__open_20210406_models.CreateFunctionRequest(
function_name=args.fc_name,
code=code,
environment_variables={"MYSQL_ENDPOING": args.mysql_endpoint, "MYSQL_USER": args.mysql_user,"MYSQL_PORT": args.mysql_port, "MYSQL_PASSWORD": args.mysql_password,"MYSQL_DBNAME": args.mysql_dbname},
handler="index.handler",
initializer="index.initializer",
runtime="python3",
instance_lifecycle_config=lifecycConfig
)
print(create_function_request)
print(args.srv_name)
print(args.fc_name)
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
client.create_function_with_options(args.srv_name, create_function_request, create_function_headers,
runtime)
ConsoleClient.log("创建函数:{}成功".format(args.fc_name))
except Exception as error:
# 如有需要,请打印 error
ConsoleClient.log(error.message)