|
| 1 | +const secret = require('../../../../secret') |
| 2 | +const ScfUtils = require('./index') |
| 3 | + |
| 4 | +class ClientTest { |
| 5 | + async scfTest() { |
| 6 | + const scf = new ScfUtils({ |
| 7 | + SecretId: secret.SecretId, |
| 8 | + SecretKey: secret.SecretKey |
| 9 | + }, ['ap-shanghai', 'ap-guangzhou']) |
| 10 | + const scfDemo = { |
| 11 | + name: 'myFunctionttest', |
| 12 | + handler: 'index.main_handler', |
| 13 | + runtime: 'Python3.6', |
| 14 | + role: 'SCF_PythonLogsRole', |
| 15 | + // eip: true, |
| 16 | + region: 'ap-shanghai', |
| 17 | + description: 'My Serverless Function', |
| 18 | + memorySize: '256', |
| 19 | + timeout: '20', |
| 20 | + tags: { |
| 21 | + mytest: 'abc' |
| 22 | + }, |
| 23 | + environment: { |
| 24 | + variables: { |
| 25 | + TEST: 'value' |
| 26 | + } |
| 27 | + }, |
| 28 | + events: [ |
| 29 | + { |
| 30 | + timer: { |
| 31 | + name: 'timer', |
| 32 | + parameters: { |
| 33 | + cronExpression: '*/6 * * * *', |
| 34 | + enable: true, |
| 35 | + argument: 'mytest argument' |
| 36 | + } |
| 37 | + } |
| 38 | + }, |
| 39 | + { |
| 40 | + apigw: { |
| 41 | + name: 'serverless', |
| 42 | + parameters: { |
| 43 | + protocols: ['http'], |
| 44 | + serviceName: 'serverless', |
| 45 | + description: 'the serverless service', |
| 46 | + environment: 'release', |
| 47 | + endpoints: [{ |
| 48 | + path: '/users', |
| 49 | + method: 'POST' |
| 50 | + }] |
| 51 | + } |
| 52 | + |
| 53 | + } |
| 54 | + } |
| 55 | + ], |
| 56 | + 'ap-shanghai': { |
| 57 | + code: { |
| 58 | + bucket: 'sls-cloudfunction-ap-shanghai-code', |
| 59 | + object: 'sls-cloudfunction-default-Album_Add_Album-1585359218.zip' |
| 60 | + }, |
| 61 | + }, |
| 62 | + 'ap-guangzhou': { |
| 63 | + code: { |
| 64 | + bucket: 'sls-cloudfunction-ap-guangzhou', |
| 65 | + object: 'sls-cloudfunction-default-hello_world-1584670117.zip' |
| 66 | + }, |
| 67 | + } |
| 68 | + } |
| 69 | + const result = await scf.deploy(scfDemo) |
| 70 | + console.log(JSON.stringify(result)) |
| 71 | + // console.log(await scf.invoke(result.FunctionName)) |
| 72 | + await scf.remove(result) |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +new ClientTest().scfTest() |
| 77 | + |
| 78 | +/* 测试结果: |
| 79 | + Creating funtion myFunction1 in ap-guangzhou ... |
| 80 | + Getting function myFunction1's configure ... |
| 81 | + Adding tags for funtion myFunction1 in ap-guangzhou ... |
| 82 | + Deploying myFunction1's triggers in ap-guangzhou. |
| 83 | + Checking function myFunction1 status ... |
| 84 | + Modify tags ... |
| 85 | + Modified tags. |
| 86 | + Checking function myFunction1 status ... |
| 87 | + Deploying timer triggers: timer. |
| 88 | + Deployed funtion undefined. |
| 89 | + {"RequestId":"ea9d3a73-1842-413a-be71-56a7bc385381","ModTime":"2020-03-27 17:12:40","CodeInfo":"","Description":"My Serverless Function","Triggers":[{"Response":{"RequestId":"210e2f21-0ac9-4259-99d3-e2abf4d1b159","TriggerInfo":{"AddTime":"2020-03-27 17:12:44","AvailableStatus":"Available","CustomArgument":"mytest argument","Enable":1,"ModTime":"2020-03-27 17:12:44","TriggerDesc":"{\"cron\":\"0 *6"}","TriggerName":"timer","Type":"timer"}}}],"Handler":"index.main_handler","CodeSize":0,"Timeout":20,"FunctionVersion":"$LATEST","MemorySize":256,"Runtime":"Python3.6","FunctionName":"myFunction1","VpcConfig":{"VpcId":"","SubnetId":""},"UseGpu":"FALSE","Environment":{"Variables":[{"Key":"TEST","Value":"value"}]},"CodeResult":"success","CodeError":"","ErrNo":0,"Namespace":"default","Role":"SCF_PythonLogsRole","InstallDependency":"FALSE","Status":"Creating","StatusDesc":"","ClsLogsetId":"","ClsTopicId":"","FunctionId":"lam-r19fhf72","Tags":[],"EipConfig":{"EipFixed":"FALSE","Eips":[]},"AccessInfo":{"Host":"","Vip":""},"Type":"Event","DeadLetterConfig":{"Type":"","Name":"","FilterType":""},"Layers":[],"L5Enable":"FALSE","AddTime":"2020-03-27 17:12:40","PublicNetConfig":{"PublicNetStatus":"ENABLE","EipConfig":{"EipStatus":"DISABLE","EipAddress":[]}},"OnsEnable":"FALSE"} |
| 90 | + { |
| 91 | + RequestId: '02ff599b-5720-4dfb-94c0-b3f333868d31', |
| 92 | + Result: { |
| 93 | + BillDuration: 2, |
| 94 | + Duration: 2, |
| 95 | + ErrMsg: '', |
| 96 | + FunctionRequestId: '02ff599b-5720-4dfb-94c0-b3f333868d31', |
| 97 | + InvokeResult: 0, |
| 98 | + Log: 'START RequestId: 02ff599b-5720-4dfb-94c0-b3f333868d31\n' + |
| 99 | + 'Event RequestId: 02ff599b-5720-4dfb-94c0-b3f333868d31\n' + |
| 100 | + '{}\n' + |
| 101 | + 'Received event: {}\n' + |
| 102 | + `Received context: {'memory_limit_in_mb': 256, 'time_limit_in_ms': 20000, 'request_id': '02ff599b-5720-4dfb-94c0-b3f333868d31', 'environment': '{"TENCENTCLOUD_SECRETID":"AKIDPH1aD0k43GtL17YuoszTJYKABNa6B8FAddTfay3WoYMb79G9QXSesbSz2yiREMdN","TENCENTCLOUD_SECRETKEY":"LtunGCMtsfkGqQmgDECkHkskse5+WennrMPJbreXE84=","TENCENTCLOUD_SESSIONTOKEN":"26Z03TWGXBrt0b3QHemtqOdM4s6vEMe6d455a7dd94c5e489a1cdea1b1126f5e8-M_KpWmubhn_Xgr0j6ULJItvuEYSCcQGWgWyvW39L8nksAfRnzKx-CsGcYXRTVyq7_SrldrOZwHgYf3lzQKXkt9qJ4tGb50VmLmaCoSWy8D8ggbbeJ4vaj_DRg_QE8ZBm6fMlSdRkKe95MqkN0Sukmj_OVjG_tv6pr-svZiAEsspT6Ga5QwuBecFl7sJOE8GpgmfUQKEa68284ryfMCd0SRZXaP1FfMefozBabrwD28lWLtwh8a7L3vklOhTIFZSL_tyZO1AGMvKasiuGjuvqm7mKQeq5fUaFJkBdblX9hbFLdQZoQ8tLxv2yz0rjiBQGTXrC901kb1NqZqJISQlAVikaqdetDIxnvrq3bI881U","TEST":"value"}', 'environ': 'TEST=value;TENCENTCLOUD_SESSIONTOKEN=26Z03TWGXBrt0b3QHemtqOdM4s6vEMe6d455a7dd94c5e489a1cdea1b1126f5e8-M_KpWmubhn_Xgr0j6ULJItvuEYSCcQGWgWyvW39L8nksAfRnzKx-CsGcYXRTVyq7_SrldrOZwHgYf3lzQKXkt9qJ4tGb50VmLmaCoSWy8D8ggbbeJ4vaj_DRg_QE8ZBm6fMlSdRkKe95MqkN0Sukmj_OVjG_tv6pr-svZiAEsspT6Ga5QwuBecFl7sJOE8GpgmfUQKEa68284ryfMCd0SRZXaP1FfMefozBabrwD28lWLtwh8a7L3vklOhTIFZSL_tyZO1AGMvKasiuGjuvqm7mKQeq5fUaFJkBdblX9hbFLdQZoQ8tLxv2yz0rjiBQGTXrC901kb1NqZqJISQlAVikaqdetDIxnvrq3bI881U;TENCENTCLOUD_SECRETID=AKIDPH1aD0k43GtL17YuoszTJYKABNa6B8FAddTfay3WoYMb79G9QXSesbSz2yiREMdN;TENCENTCLOUD_SECRETKEY=LtunGCMtsfkGqQmgDECkHkskse5+WennrMPJbreXE84=;SCF_NAMESPACE=default', 'function_version': '$LATEST', 'function_name': 'myFunction1', 'namespace': 'default'}\n` + |
| 103 | + 'Hello world\n' + |
| 104 | + '\n' + |
| 105 | + 'END RequestId: 02ff599b-5720-4dfb-94c0-b3f333868d31\n' + |
| 106 | + 'Report RequestId: 02ff599b-5720-4dfb-94c0-b3f333868d31 Duration:2ms Memory:256MB MemUsage:11.2188MB', |
| 107 | + MemUsage: 11763712, |
| 108 | + RetMsg: '"Hello World"' |
| 109 | + } |
| 110 | + } |
| 111 | + Deleteing funtion myFunction1 ... |
| 112 | + Removed function and triggers. |
| 113 | +*/ |
0 commit comments