This topic describes how to use Function Compute SDKs.

SDKs

SDK Download link Installation method User guide
Golang SDK go-fc-open-20210406 go get github.com/alibabacloud-go/fc-open-20210406 Get started
Java SDK java-fc-open-20210406 maven-fc-open-20210406 Get started
Python 3 SDK python3-fc-open-20210406 pip install alibabacloud-fc-open20210406 Get started
PHP SDK php-fc-open-20210406 composer require alibabacloud/fc-open-20210406 Get started
Node.js SDK nodejs-fc-open-20210406 npm i @alicloud/fc-open20210406 Get started
C++ SDK cpp-fc-open-20210406 Installation documentation N/A
C# SDK csharp-fc-open-20210406 dotnet add package AlibabaCloud.SDK.FC-Open20210406 Get started

Use SDKs

This section provides sample code of using the SDK for each supported language. In the examples, SDKs are used to call the CreateService operation.

Note To use the sample code, you must replace the following parameters with actual values:

package main

import (
  "os"
  
  fc_open20210406  "github.com/alibabacloud-go/fc-open-20210406/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/client"
  "github.com/alibabacloud-go/tea/tea"
)

func CreateClient (accessKeyId *string, accessKeySecret *string) (_result *fc_open20210406.Client, _err error) {
  config := &openapi.Config{
    // Your AccessKey ID.
    AccessKeyId: accessKeyId,
    // Your AccessKey secret.
    AccessKeySecret: accessKeySecret,
  }
  
  config.Endpoint = tea.String(${endpoint})
  _result = &fc_open20210406.Client{}
  _result, _err = fc_open20210406.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient(tea.String(${accessKeyId}), tea.String(${accessKeySecret}))
  if _err != nil {
    return _err
  }

  createServiceRequest := &fc_open20210406.CreateServiceRequest{
    ServiceName: tea.String("testServiceName"),
  }
  _, _err = client.CreateService(createServiceRequest)
  if _err != nil {
    return _err
  }
  return _err
}

func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}

# -*- coding: utf-8 -*-
import sys

from typing import List

from alibabacloud_fc_open20210406.client import Client as FC_Open20210406Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_fc_open20210406 import models as fc__open_20210406_models

class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> FC_Open20210406Client:
        config = open_api_models.Config(
            # Your AccessKey ID.
            access_key_id=access_key_id,
            # Your AccessKey secret.
            access_key_secret=access_key_secret
        )
        # The endpoint that you use to access Function Compute.
        config.endpoint = ${endpoint}
        return FC_Open20210406Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client(${accessKeyId}, ${accessKeySecret})
        create_service_request = fc__open_20210406_models.CreateServiceRequest(
            service_name='testServiceName'
        )
        # Write your own code to process the response of the API operation.
        client.create_service(create_service_request)

if __name__ == '__main__':
    Sample.main(sys.argv[1:])

<?php

namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\FCOpen\V20210406\FCOpen;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\FCOpen\V20210406\Models\CreateServiceRequest;

class Sample {
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // Your AccessKey ID.
            "accessKeyId" => $accessKeyId,
            // Your AccessKey secret.
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint that you use to access Function Compute.
        $config->endpoint = ${endpoint};
        return new FCOpen($config);
    }

    public static function main($args){
        $client = self::createClient(${accessKeyId}, ${accessKeySecret});
        $createServiceRequest = new CreateServiceRequest([
            "serviceName" => "testServiceName"
        ]);
        $client->createService($createServiceRequest);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));

import FC_Open20210406, * as $FC_Open20210406 from '@alicloud/fc-open20210406';
import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import * as $tea from '@alicloud/tea-typescript';


export default class Client {
  static createClient(accessKeyId: string, accessKeySecret: string): FC_Open20210406 {
    let config = new $OpenApi.Config({
      // Your AccessKey ID.
      accessKeyId: accessKeyId,
      // Your AccessKey secret.
      accessKeySecret: accessKeySecret,
    });
    // The endpoint that you use to access Function Compute.
    config.endpoint = ${endpoint};
    return new FC_Open20210406(config);
  }

  static async main(args: string[]): Promise<void> {
    let client = Client.createClient(${accessKeyId}, ${accessKeySecret});
    let createServiceRequest = new $FC_Open20210406.CreateServiceRequest({
      serviceName: "testServiceName",
    });
    await client.createService(createServiceRequest);
  }

}

Client.main(process.argv.slice(2));

"use strict";

const {
  default: Client,
  InvokeFunctionHeaders,
  InvokeFunctionRequest,
} = require("@alicloud/fc-open20210406");
const { Config } = require("@alicloud/openapi-client");
const { RuntimeOptions } = require("@alicloud/tea-util");
const runtime = new RuntimeOptions({});

let client;

exports.initialize = function (context, callback) {
  const {
    credentials: { accessKeyId, accessKeySecret, securityToken },
    accountId,
  } = context;
  const config = new Config({
    accessKeyId,
    accessKeySecret,
    securityToken,
    endpoint: `${accountId}.ap-southeast-1.fc.aliyuncs.com`,
    readTimeout: 10000000,
    connectTimeout: 10000000,
  });
  client = new Client(config);
  callback(null, "");
};

exports.handler = async (event, context, callback) => {
  const { key1, key2, ke3 } = JSON.parse(event.toString());

  let invokeFunctionHeaders = new InvokeFunctionHeaders({
    xFcInvocationType: "Async",
    xFcLogType: "None",
    xFcStatefulAsyncInvocationId: taskId,
  });

  let invokeFunctionRequest = new InvokeFunctionRequest({
    qualifier: "LATEST",
    body: Buffer.from(
      JSON.stringify({
        key1
      })
    ),
  });

  try {
    const { headers } = await client.invokeFunctionWithOptions(
      "serviceName",
      "functionName",
      invokeFunctionRequest,
      invokeFunctionHeaders,
      runtime
    );
    callback(null, headers["x-fc-stateful-async-invocation-id"]);
  } catch (error) {
    callback(error, null);
  }
};

package com.aliyun.sample;

import com.aliyun.tea.*;
import com.aliyun.fc_open20210406.*;
import com.aliyun.fc_open20210406.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;

public class Sample {
    public static com.aliyun.fc_open20210406.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // Your AccessKey ID.
                .setAccessKeyId(accessKeyId)
                // Your AccessKey secret.
                .setAccessKeySecret(accessKeySecret);
        // The endpoint that you use to access Function Compute.
        config.endpoint = ${endpoint};
        return new com.aliyun.fc_open20210406.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.fc_open20210406.Client client = Sample.createClient(${accessKeyId}, ${accessKeySecret});
        CreateServiceRequest createServiceRequest = new CreateServiceRequest()
                .setServiceName("testServiceName");
        client.createService(createServiceRequest);
    }
}

#include <alibabacloud/fc__open_20210406.hpp>
#include <alibabacloud/open_api.hpp>
#include <boost/any.hpp>
#include <iostream>
#include <map>

using namespace std;

Alibabacloud_FC-Open20210406::Client createClient(shared_ptr<string> accessKeyId, shared_ptr<string> accessKeySecret) {
  shared_ptr<Alibabacloud_OpenApi::Config> config = make_shared<Alibabacloud_OpenApi::Config>(map<string, boost::any>({
    // Your AccessKey ID.
    {"accessKeyId", !accessKeyId ? boost::any() : boost::any(*accessKeyId)},
    // Your AccessKey secret.
    {"accessKeySecret", !accessKeySecret ? boost::any() : boost::any(*accessKeySecret)}
  }));
  // The endpoint that you use to access Function Compute.
  config->endpoint = make_shared<string>(${endpoint});
  return Alibabacloud_FC-Open20210406::Client(config);
}

int main(int argc, char *args[]) {
  args++;
  shared_ptr<Alibabacloud_FC-Open20210406::Client> client = make_shared<Alibabacloud_FC-Open20210406::Client>(createClient(make_shared<string>(${accessKeyId}), make_shared<string>(${accessKeySecret})));
  shared_ptr<Alibabacloud_FC-Open20210406::CreateServiceRequest> createServiceRequest = make_shared<Alibabacloud_FC-Open20210406::CreateServiceRequest>(map<string, boost::any>({
    {"serviceName", boost::any(string("testServiceName"))}
  }));
  client->createService(createServiceRequest);
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

using Tea;
using Tea.Utils;


namespace AlibabaCloud.SDK.Sample
{
    public class Sample 
    {
        public static AlibabaCloud.SDK.FC_Open20210406.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                // Your AccessKey ID.
                AccessKeyId = accessKeyId,
                // Your AccessKey secret.
                AccessKeySecret = accessKeySecret,
            };
            // The endpoint that you use to access Function Compute.
            config.Endpoint = ${endpoint};
            return new AlibabaCloud.SDK.FC_Open20210406.Client(config);
        }

        public static void Main(string[] args)
        {
            AlibabaCloud.SDK.FC_Open20210406.Client client = CreateClient(${accessKeyId}, ${accessKeySecret});
            AlibabaCloud.SDK.FC_Open20210406.Models.CreateServiceRequest createServiceRequest = new AlibabaCloud.SDK.FC_Open20210406.Models.CreateServiceRequest
            {
                ServiceName = "testServiceName",
            };
            // Write your own code to process the response of the API operation.
            client.CreateService(createServiceRequest);
        }


    }
}

OpenAPI Explorer

To view more SDK demos in different languages for calling API operations and debug your code, visit OpenAPI Explorer.