跳至主要内容

[AWS] Lambda

keywords: aws, s3, lambda

使用 Node.js @ AWS Docs

部署(Deploy)

# ./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

/* 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);
}
});