通过函数计算的Custom Runtime,您可以在函数计算平台使用C++来编写函数。本文介绍快速部署和调用C++函数的详细步骤。
前提条件
说明 如果您已安装Funcraft可直接跳转至步骤二:部署和调用函数。
步骤一:准备环境
安装Funcraft,最简单的方式就是直接下载可执行的二进制文件。
通过函数计算的Custom Runtime,您可以在函数计算平台使用C++来编写函数。本文介绍快速部署和调用C++函数的详细步骤。
安装Funcraft,最简单的方式就是直接下载可执行的二进制文件。
fun --version
检查安装是否成功。fun config
配置Funcraft。然后按照提示依次配置Account ID、Access Key ID、Access Key Secret、Default region name。fun config
Aliyun Account ID 1234xxx
Aliyun Access Key ID xxxx
Aliyun Access Key Secret xxxx
Default region name cn-xxxx
The timeout in seconds for each SDK client invoking 300
The maximum number of retries for each SDK client 5
Allow to anonynously report usage statistics to improve the tool over time? (Y/n)
git clone https://github.com/awesome-fc/fc-custom-demo
cd fc-custom-demo
cd cpp-demo
make deploy
docker build -t fc-cpp-runtime -f build-image/Dockerfile build-image
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM aliyunfc/runtime-custom:base
---> 5bbdcf6377bd
...
Step 3/3 : RUN apt-get install -y cmake
---> Using cache
---> a244cd26cec2
Successfully built a244cd26cec2
Successfully tagged fc-cpp-runtime:latest
docker run --rm -it -v $(pwd):/tmp fc-cpp-runtime bash -c "cd /tmp && ./build.sh"
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
...
Scanning dependencies of target cppruntime
[ 33%] Building CXX object CMakeFiles/cppruntime.dir/src/handler.cpp.o
[ 66%] Building CXX object CMakeFiles/cppruntime.dir/src/logging.cpp.o
[100%] Linking CXX shared library /tmp/bin/libcppruntime.so
...
-- Build files have been written to: /tmp/sample/release
...
[100%] Built target bootstrap
fun deploy -y
Waiting for service cpp_demo to be deployed...
Waiting for function fc_cpp_event to be deployed...
Waiting for packaging function fc_cpp_event code...
The function fc_cpp_event has been packaged. A total of 2 files were compressed and the final size was 446.51 KB
function fc_cpp_event deploy success
Waiting for function fc_cpp_http to be deployed...
Waiting for packaging function fc_cpp_http code...
The function fc_cpp_http has been packaged. A total of 2 files were compressed and the final size was 446.51 KB
Waiting for HTTP trigger http_t to be deployed...
triggerName: http_t
methods: [ 'GET', 'POST', 'PUT', 'DELETE' ]
url: https://123456789.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/cpp_demo/fc_cpp_http/
Http Trigger will forcefully add a 'Content-Disposition: attachment' field to the response header, which cannot be overwritten
and will cause the response to be downloaded as an attachment in the browser. This issue can be avoided by using CustomDomain.
trigger http_t deploy success
function fc_cpp_http deploy success
service cpp_demo deploy success
Detect 'DomainName:Auto' of custom domain 'my_domain'
Fun will reuse the temporary domain http://17904911-123456789.test.functioncompute.com, expired at 2020-05-06 20:41:51, limited by 1000 per day.
Waiting for custom domain my_domain to be deployed...
custom domain my_domain deploy success
fun invoke cpp_demo/fc_cpp_event -e "Hello World"
...
========= FC invoke Logs begin =========
/invoke is called.
FC Invoke Start RequestId: bf282a87-0f0b-4953-b159-a31792bad22a
2020-04-27T08:01:08 bf282a87-0f0b-4953-b159-a31792bad22a [INFO] handling invoke
FC Invoke End RequestId: bf282a87-0f0b-4953-b159-a31792bad22a
Duration: 9.11 ms, Billed Duration: 100 ms, Memory Size: 512 MB, Max Memory Used: 4.25MB
========= FC invoke Logs end =========
FC Invoke Result:
Hello World
$ curl http://17904911-123456789.test.functioncompute.com -d "Hello World"
Hello World
在文档使用中是否遇到以下问题
更多建议
匿名提交