The SDK of this version is dependent on the third-party HTTP library requests.
Python 3.6+
Install the official release version through PIP (taking Linux as an example):
$ pip install xl-aliyun-fc2
You can also install the unzipped installer package directly:
$ sudo python setup.py install
# -*- coding: utf-8 -*-
import fc2
import zipfile
import base64
# To know the endpoint and access key id/secret info, please refer to:
# https://help.aliyun.com/document_detail/52984.html
client = fc2.Client(
endpoint='<Your Endpoint>',
accessKeyID='<Your AccessKeyID>',
accessKeySecret='<Your AccessKeySecret>')
# Create service.
client.create_service('demo')
zipFileBase64 = ''
with open('file.zip', 'rb') as f:
content = f.read()
zipFileBase64 = base64.b64encode(content).decode()
# Create function.
client.create_function('demo',
{
'functionName':'test_func',
'runtime': 'python3',
'handler': 'index.handler',
'code': {
'zipFile': zipFileBase64
},
'environmentVariables': {'testKey': 'testValue'}
}
)
# Invoke function synchronously.
client.invoke_function('demo', 'test_func')