-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-lambda.js
32 lines (27 loc) · 933 Bytes
/
upload-lambda.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs')
const path = require('path')
const FCClient = require('@alicloud/fc2')
const compressing = require('compressing')
const { accessKeyId, accessKeySecret, accountId, region, serviceName } = require('./common/constants/aliyun')
const client = new FCClient(accountId, {
accessKeyID: accessKeyId,
accessKeySecret,
region,
})
const funcName = process.argv.pop()
const dir = path.resolve(__dirname, funcName)
async function handleUpdate() {
try {
await compressing.zip.compressDir(`${dir}/dist/index.js`, `${dir}/dist.zip`)
const codeZip = fs.readFileSync(`${dir}/dist.zip`)
const resp = await client.updateFunction(serviceName, funcName, {
code: {
zipFile: codeZip.toString('base64'),
},
})
console.log('update function: %j', resp.data)
} catch (err) {
console.error(err)
}
}
handleUpdate().then()