Python SDK
A synchronous function execution SDK is used as an example. To use the sample code, you must add the SDK dependency with the same language.
SDK Info |
Description |
---|---|
Version |
3.0.97 |
Installation |
pip install huaweicloudsdkfunctiongraph |
Links |
The request/response parameters and example requests/responses of the SDK are the same as those of the corresponding APIs. For details about the parameters and examples, see the API for executing a function synchronously.
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkfunctiongraph.v2.region.functiongraph_region import FunctionGraphRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkfunctiongraph.v2 import * if __name__ == "__main__": # This example is only used for testing purposes. Do not hardcode your AK/SK in the production environment. ak = "<YOUR AK>" sk = "<YOUR SK>" credentials = BasicCredentials(ak, sk) \ client = FunctionGraphClient.new_builder() \ .with_credentials(credentials) \ .with_region(FunctionGraphRegion.value_of("<region>")) \ .build() try: request = InvokeFunctionRequest() request.function_urn = "urn:fss:<region>:<project_id>:function:default:<func_name>:<version>" response = client.invoke_function(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
Obtain AK/SK, region (endpoint), and project_id by referring to AK/SK Signing and Authentication Guide.
Obtain func_name and version from the function details page.
X-CFF-Request-Version indicates the response body format. v0: text format; v1: JSON format. Select this format when using an SDK.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.