函数操作
所有文档
menu

函数计算 CFC

函数操作

产品详情立即开通

各接口的请求参数和响应参数说明请参考函数操作

创建函数

如下代码可以创建一个CFC函数:

public void testCreateFunction(CfcClient cfcClient) {
        String zipFile = "UEsDBBQACAgIAGumvE4AAAAAAAAAAAAAAAAIAAAAaW5kZXgucHkVykEKgCAQQNG94B2m3FQk0i66TeWUgYwxjVG3z/7y8U3l8sVuOcgh3XC+EhJpZcB2FtbkD9onyLLZ8RetPG4QZvIRucEbSfpykeAj7aQVlBglM0E9BIwx1R9QSwcIunbW71oAAABhAAAAUEsBAhQAFAAICAgAa6a8Trp21u9aAAAAYQAAAAgAAAAAAAAAAAAAAAAAAAAAAGluZGV4LnB5UEsFBgAAAAABAAEANgAAAJAAAAAAAA==";
        Code code = new Code();       //CFC函数代码
        code.setZipFile(zipFile);
        code.setPublish(false);
        code.setDryRun(true);
        String description = "test api";
        HashMap<String, String> variables = new HashMap<String, String>();
        variables.put("additional", "aaa");
        Environment environment = new Environment();
        environment.setVariables(variables);
        long time = System.currentTimeMillis();
        String functionName = "test-" + String.valueOf(time);  //函数名称
        String handler = "index.handler";
        Integer memorySize = 256;
        String runtime = "python2";
        Integer timeOut = 5;

        CreateFunctionRequest request = new CreateFunctionRequest(functionName, null)
                .withCode(code)
                .withEnvironment(environment)
                .withHandler(handler)
                .withMemorySize(memorySize)
                .withRuntime(runtime)
                .withTimeout(timeOut);
        CreateFunctionResponse response = cfcClient.createFunction(request);
        System.out.println(response);   //创建成功,获取新建函数信息
    }

函数列表

如下代码可列出用户所在区域的所有函数:

public void testListFunctions(CfcClient cfcClient) {
        ListFunctionsResponse response = cfcClient.listFunctions("ALL", null, null);
        System.out.println(response);
    }

获取函数信息

如下代码可以查询用户单个函数:

public void testGetFunction(CfcClient cfcClient) {
        String functionName = "test-1559096559957"; //已经存在的函数名称
        GetFunctionResponse response = cfcClient.getFunction(functionName, "$LATEST");
        System.out.println(response);
    }

删除函数

如下代码用于删除用户函数:

public void testDeleteFunction(CfcClient cfcClient) {
        String functionName = "test-1557893401910"; //已经存在的函数名称
        cfcClient.deleteFunction(functionName, null);
    }

更新函数代码

如下代码用于更新指定函数代码:

public void testUpdateFunctionCode(CfcClient cfcClient) {
        String zipFile = "UEsDBBQACAgIAIumvE4AAAAAAAAAAAAAAAAIAAAAaW5kZXgucHkVjMsOgjAQAO9N+g8rXNTYVEHk8TMG6EJJmi2pW5C/t85xMpn8pOMn6GEhjbTBerD1JEUO6qpg9GahuYPIk2r+RgqDE9iejMNwxg2Jb6kixi9fOikgEZBjIMgKwv1t0Tn/KMpn9aqb9t4PYxrMNvsBUEsHCGs/OTtwAAAAdwAAAFBLAQIUABQACAgIAIumvE5rPzk7cAAAAHcAAAAIAAAAAAAAAAAAAAAAAAAAAABpbmRleC5weVBLBQYAAAAAAQABADYAAACmAAAAAAA=";
        Code code = new Code();
        code.setZipFile(zipFile);
        Boolean publish = true;
        Boolean dryRun = false;
        String functionName = "test-1559048290101"; //已经存在的函数名称

        UpdateFunctionCodeRequest request = new UpdateFunctionCodeRequest()
                .withFunctionName(functionName)
                .withZipFile(zipFile)
                .withPublish(publish)
                .withDryRun(dryRun);
        UpdateFunctionCodeResponse response = cfcClient.updateFunctionCode(request);
        System.out.println(response);

    }

获取函数配置

如下代码用于获取指定函数的配置信息:

public void testGetFunctionConfiguration(CfcClient cfcClient) {
        String functionName = "test-1557387367523"; //已经存在的函数名称
        GetFunctionConfigurationResponse response = cfcClient.getFunctionConfiguration(functionName, null);
        System.out.println(response);
    }

更新函数配置

如下代码用于修改函数配置:

public void testUpdateFunctionConfiguration(CfcClient cfcClient) {
        HashMap<String, String> variables = new HashMap<String, String>();
        variables.put("additional1", "bbbb");
        Environment environment = new Environment();
        environment.setVariables(variables);
        String functionName = "test-1559096559957"; //已经存在的函数名
        String desc = "123";
        Integer timeout = 3;
        String zipFile = "UEsDBBQACAgIAIumvE4AAAAAAAAAAAAAAAAIAAAAaW5kZXgucHkVjMsOgjAQAO9N+g8rXNTYVEHk8TMG6EJJmi2pW5C/t85xMpn8pOMn6GEhjbTBerD1JEUO6qpg9GahuYPIk2r+RgqDE9iejMNwxg2Jb6kixi9fOikgEZBjIMgKwv1t0Tn/KMpn9aqb9t4PYxrMNvsBUEsHCGs/OTtwAAAAdwAAAFBLAQIUABQACAgIAIumvE5rPzk7cAAAAHcAAAAIAAAAAAAAAAAAAAAAAAAAAABpbmRleC5weVBLBQYAAAAAAQABADYAAACmAAAAAAA=";
        Code code = new Code();
        code.setZipFile(zipFile);
        code.setPublish(false);
        code.setDryRun(true);

        UpdateFunctionConfigurationRequest request = new UpdateFunctionConfigurationRequest(functionName, null)
                .withEnvironment(environment)
                .withTimeout(timeout)
                .withCode(code)
                .withFunctionName(functionName);
        UpdateFunctionConfigurationResponse response = cfcClient.updateFunctionConfiguration(request);
        System.out.println(response);
    }
上一篇
CfcClient
下一篇
函数调用