本文提供调用函数计算SDK的使用说明。

SDK列表

SDK列表 下载链接 快捷安装方式 详细使用手册
Golang SDK go-fc-open-20210406 go get github.com/alibabacloud-go/fc-open-20210406 开始使用
Java SDK java-fc-open-20210406 maven-fc-open-20210406 开始使用
Python 3 SDK python3-fc-open-20210406 pip install alibabacloud-fc-open20210406 开始使用
PHP SDK php-fc-open-20210406 composer require alibabacloud/fc-open-20210406 开始使用
Node.js SDK nodejs-fc-open-20210406 npm i @alicloud/fc-open20210406 开始使用
C++ SDK cpp-fc-open-20210406 安装文档
C# SDK csharp-fc-open-20210406 dotnet add package AlibabaCloud.SDK.FC-Open20210406 开始使用

SDK使用示例

本文档针对每种语言的SDK提供创建服务API的代码示例供您参考。

说明 下文中的代码示例需填写以下参数:

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{
    // 您的AccessKey ID
    AccessKeyId: accessKeyId,
    // 您的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(
            # 您的AccessKey ID
            access_key_id=access_key_id,
            # 您的AccessKey Secret
            access_key_secret=access_key_secret
        )
        # 访问的域名
        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'
        )
        # 复制代码运行请自行打印API的返回值
        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([
            // 您的AccessKey ID
            "accessKeyId" => $accessKeyId,
            // 您的AccessKey Secret
            "accessKeySecret" => $accessKeySecret
        ]);
        // 访问的域名
        $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({
      // 您的AccessKey ID
      accessKeyId: accessKeyId,
      // 您的AccessKey Secret
      accessKeySecret: accessKeySecret,
    });
    // 访问的域名
    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()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        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>({
    // 您的AccessKey ID
    {"accessKeyId", !accessKeyId ? boost::any() : boost::any(*accessKeyId)},
    // 您的AccessKey Secret
    {"accessKeySecret", !accessKeySecret ? boost::any() : boost::any(*accessKeySecret)}
  }));
  // 访问的域名
  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
            {
                // 您的AccessKey ID
                AccessKeyId = accessKeyId,
                // 您的AccessKey Secret
                AccessKeySecret = accessKeySecret,
            };
            // 访问的域名
            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",
            };
            // 复制代码运行请自行打印API的返回值
            client.CreateService(createServiceRequest);
        }


    }
}

开发者门户

如需查看更多API级别的多语言SDK Demo并进行调试,请访问开发者门户