aliyun / fc-nodejs-sdk Goto Github PK
View Code? Open in Web Editor NEWThe Node.js SDK of FunctionCompute.
License: MIT License
The Node.js SDK of FunctionCompute.
License: MIT License
FC有一些自定义的header,例如x-fc-invocation-type
, x-fc-trace-id
,需要SDK支持设置自定义的header。
自定义域名只能用在http触发器上吗? 没有设置http触发器函数必须要用*.fc.aliyuncs.com做endpoint吗? 打算用CDN的域名代替endpoint
var FCClient = require('@alicloud/fc2');
var client = new FCClient('xxxx', {
accessKeyID: 'xxx',
accessKeySecret: 'xxx',
region: 'cn-shanghai',
timeout: '180000', // 配置超时
});
client
.invokeFunction(
'xxxxx',
'runScript',
JSON.stringify({
func: '{ headers: request.hello }',
request: {
hello: '@alipay/b' // #1
}
})
)
.then(resp => {
console.log('resp', resp);
})
.catch(err => {
// TODO
console.error('err', err);
});
返回
resp { headers:
{ 'access-control-expose-headers': 'Date,x-fc-request-id,x-fc-error-type,x-fc-code-checksum,x-fc-invocation-duration,x-fc-max-memory-usage,x-fc-log-result,x-fc-invocation-code-version',
'content-length': '2',
'content-type': 'application/octet-stream',
'x-fc-code-checksum': '10424674220137372625',
'x-fc-invocation-duration': '5',
'x-fc-invocation-service-version': 'LATEST',
'x-fc-max-memory-usage': '25.18',
'x-fc-request-id': '528c084a-ab72-428f-ae96-0ac3e21e70ce',
date: 'Tue, 24 Dec 2019 06:32:49 GMT' },
data: '{}' }
期望返回:
resp { headers:
{ 'access-control-expose-headers': 'Date,x-fc-request-id,x-fc-error-type,x-fc-code-checksum,x-fc-invocation-duration,x-fc-max-memory-usage,x-fc-log-result,x-fc-invocation-code-version',
'content-length': '22',
'content-type': 'application/octet-stream',
'x-fc-code-checksum': '10424674220137372625',
'x-fc-invocation-duration': '5',
'x-fc-invocation-service-version': 'LATEST',
'x-fc-max-memory-usage': '25.10',
'x-fc-request-id': '528977c4-b946-4e9a-a325-e9ee9c0def78',
date: 'Tue, 24 Dec 2019 06:28:42 GMT' },
data: '{"headers":"@alipay/b"}' }
注意 data 部分。
当把 #1
行代码从 @alipay/b
改成 @alipay/
,返回才符合预期。
Rt, api文档没法访问, 辛苦修一下
我以前使用 aws 的lambda,它可以自定义授权,比如授权函数为 A 而B 需要授权,那么调用B之前会先调用A,如果A 里授权错误 会终止,授权成功会把自定义的数据传递给B
我现在需要把 aws 的代码部署到 阿里云来,目前看来唯一的困惑是这个,阿里fc 是否支持这个功能?我们的其他服务等等已经在阿里云跑了,不想将这个服务单独放在 aws 或者整个迁移到 aws
如题
使用这个SDK的get()方法触发函数计算的任务,返回:
GET /proxy/script/exportBillExcel/ failed with 403. requestid: 36224761-90de-4299-8c63-f9d77c2306b9, message: The request signature we calculated does not match the signature you provided. Check your access key and signing method..
这个问题怎样解决?
管理控制台页面endpoint构造规则
https://$ACCOUNT_ID.$REGION$INTERNEL.fc.aliyuncs.com
代码中构造方法为
this.endpoint = `${protocol}://${accountid}.fc.${region}${internal}.aliyuncs.com`;
this.host = `${accountid}.fc.${region}${internal}.aliyuncs.com`;
When I use this SDK to invoke my FC function, I got a 400 error, while do the POST request. it is said:
{"ErrorCode":"MissingRequiredHeader","ErrorMessage":"required HTTP header Date was not specified"}
And I checked the http.request method which automatically bundled by tool like parcel. Then I found, it's forbidden for frontend to do http request with date
header (check MDN for more).
Is there any suggestion to me for invoking the FC function from frontend?
文档里写的地址是 POST /services/{serviceName.qualifier}/functions/{functionName} HTTP/1.1 。
但是 SDK 实际调用的是 /services/${getServiceName(serviceName, qualifier)}/functions/${functionName}/invocations
。
报错:
Error [FCundefinedError]: POST /services/xxxx/functions/xxxx/invocations failed with 400. requestid: undefined, message: undefined.
at Client.request (/node_modules/@alicloud/fc2/lib/client.js:177:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
code: undefined
}
github:
client.js Line 90
this.timeout = Number.isFinite(config.timeout) ? config.timeout : 10000; // default is 10s
But, install version 1.2.0 code from npm, the code is
this.timeout = 10000; // 10s
代码:
await client.invokeFunction('bff-service', 'getList', null);
错误提示:Function with http trigger(name: httpTrigger) can only be invoked with http trigger URL.
目前有方法调用http触发器的函数吗?
我们有一些自定义的header返回,例如x-fc-error-type
, x-fc-request-id
, x-fc-log-result
等。
当前接口返回的是response body,能否直接将response返回?
这样改动会有兼容性问题吗? @JacksonTian
在函数计算服务中,invokeFunction时的event可以是任意的payload,SDK不应该将它进行stringify的转换。
现在我使用sdk中的getfunction 可以正常访问函数 但是用post 访问函数 返回403
创建service时 传入参数 vpcConfig 报错400 - Argument 'vpcConfig' is not supported。
我已经根据 阿里云官网文档来做的
API文档
FC文档
vpcConfig = { 'securityGroupId':'sg-1111', 'vSwitchIds':['vsw-1111'], 'vpcId':'vpc-1111 }
service = await fc.createService(serviceName, { description: serviceDescription, vpcConfig: vpcConfig });
{"ErrorCode":"InvalidArgument","ErrorMessage":"Argument 'vpcConfig' is not supported"}
/2016-08-15/services +4ms
lambda request headers: {"accept":"application/json","date":"Fri, 15 Jun 2018 03:22:03 GMT","host":"111111111.cn-shenzhen.fc.aliyuncs.com","user-agent":"Node.js(v9.10.1) OS(darwin/x64) SDK(@alicloud/[email protected])","x-fc-account-id":"222222","content-type":"application/json","content-length":59,"content-md5":"11111111111=","authorization":"FC LTAIldIgp2DLHiGG="} +1ms
httpx > POST /2016-08-15/services HTTP/1.1 +14ms
httpx > accept: application/json +0ms
httpx > date: Fri, 15 Jun 2018 03:22:03 GMT +1ms
httpx > host: 111111.cn-shenzhen.fc.aliyuncs.com +0ms
httpx > user-agent: Node.js(v9.10.1) OS(darwin/x64) SDK(@alicloud/[email protected]) +0ms
httpx > x-fc-account-id: 111111111 +0ms
httpx > content-type: application/json +0ms
httpx > content-length: 59 +0ms
httpx > content-md5: MDJhZWRkM2M= +0ms
httpx > authorization: FC LTAIldI5dNkEtEi/RZw= +0ms
httpx > Connection: keep-alive +0ms
httpx > +0ms
httpx > +0ms
httpx < HTTP/1.1 400 Bad Request +0ms
httpx < access-control-allow-origin: +0ms
httpx < access-control-expose-headers: Date,x-fc-request-id,x-fc-error-type,x-fc-code-checksum,x-fc-max-memory-usage,x-fc-log-result,x-fc-invocation-code-version +1ms
httpx < content-type: application/json; charset=utf-8 +0ms
httpx < x-fc-error-type: FCCommonError +0ms
httpx < x-fc-request-id: 96-a60afc60d7b +0ms
httpx < date: Fri, 15 Jun 2018 03:22:03 GMT +0ms
httpx < content-length: 86 +0ms
lambda response status: 400 +0ms
lambda response headers: {"access-control-allow-origin":"","access-control-expose-headers":"Date,x-fc-request-id,x-fc-error-type,x-fc-code-checksum,x-fc-max-memory-usage,x-fc-log-result,x-fc-invocation-code-version","content-type":"application/json; charset=utf-8","x-fc-error-type":"FCCommonError","x-fc-request-id":"962b1-7afc60d7b","date":"Fri, 15 Jun 2018 03:22:03 GMT","content-length":"86"} +1ms
httpx +0ms
httpx {"ErrorCode":"InvalidArgument","ErrorMessage":"Argument 'vpcConfig' is not supported"} +0ms
FCInvalidArgumentError: POST /services failed with 400. requestid: 9625-7080, message: Argument 'vpcConfig' is not supported.
at Client.request (/Applications/mampstack-5.5.30-0/apache2/htdocs/ali-func/fcvpc/node_modules/.2.0.3@@alicloud/fc2/lib/client.js:148:19)
at
at process._tickCallback (internal/process/next_tick.js:118:7)
Options:
code function代码
code: {
zipFile: fs.readFileSync(path.join(__dirname, 'figures/test.zip'), 'base64')
}
请问 figures/test.zip 的目录结构?
{
"errorMessage": "Module '/code/counter.js' is missing.",
"errorType": "Error",
"stackTrace": [
"Error: Module '/code/counter.js' is missing."
]
}
Lines 69 to 70 in de6d932
如果config.endpoint指定了的话,this.host应该从config.endpoint里取,而不是从头拼凑
/services/${getServiceName(serviceName, qualifier)}/functions/${functionName}/on-demand-config
这个接口,帮忙实现一下?因为没有文档,我只是本地简单测试了一下可用,希望维护者帮忙提交一下
java、golang里面有实现。
fs是不是不能在浏览器里面使用的,想知道有没有可以在浏览器里面使用的函数计算的sdk。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.