PJCHENder 未整理筆記

[AWS] Lambda

2020-04-06

[AWS] Lambda

keywords: aws, s3, lambda

使用 Node.js @ AWS Docs

部署(Deploy)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# ./deploy.sh

rm tmp/*

# 將專案打包成 zip
zip -9 -r function.zip . -x '*.git*' '*.vscode*' 'node_modules/@ffmpeg-installer/darwin-x64/*'

echo "Uploading to AWS lambda ..."

# 上傳 AWS Lambda
aws lambda update-function-code --function-name extractAudioToGCS --zip-file fileb://function.zip

# 移除壓縮檔
rm function.zip

本地執行 Lambda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Invoke Lambda locally */
const lambda = new AWS.Lambda({
region: 'us-west-2',
});

var params = {
FunctionName: 'afterVideoUploaded',
InvocationType: 'RequestResponse',
LogType: 'Tail',
Payload: JSON.stringify({
objectKeyOnS3: 'facevideo/1566458780000bQySkm8h_video.webm',
}),
};

lambda.invoke(params, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
}
});

掃描二維條碼,分享此文章