[英]AWS lambda destination not triggering
我的child lambda
在目的地沒有被Main Lambda
觸發。 它僅在我在 aws cli 中使用--invocation-type Event
時觸發。 它不會在測試或實時模式下觸發。 Main lambda 在這兩種方式上都工作正常,但它只是在沒有 cli 命令的情況下不會觸發目標 lambda。
完整的 aws cli 有效。(但我不會使用 aws-cli 來觸發。它應該由 Cloudfront 觸發)
aws lambda invoke --function-name main-lambda --cli-binary-format raw-in-base64-out --payload '{"test": 15}' --invocation-type Event response.json
主 Lambda
const https = require("https");
exports.handler = async (event, context, callback) => {
await post("https://example.com/notify", {
type: "viewer-response",
event,
context,});
let response = "";
try {
response = event.Records[0].cf.response;
} catch (e) {
response = event; //For debug purposes
}
// Added this, but not working either.
//response.headers['x-amz-invocation-type'] = [{key: 'X-Amz-Invocation-Type', value: 'Event'}];
return response;
};
孩子 Lambda
const https = require('https');
exports.handler = async (event,context,callback) => {
console.log("Triggered Child Lambda");
await post("https://example.com/notify", {
type: "onSuccess-response",
event,
context, });
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response; // I don't need this. This comes from base
}
我知道Main Lambda
應該用Event
類型調用,因為它需要異步才能調用目標 lambda 但我無法找到一種方法來做到這一點。 我嘗試將環境變量添加到 lambda function 但它也沒有用。
這是預期的行為。 CloudFront 使用同步調用模式調用 Lambdas。 該服務等待來自 Lambda 的響應。目的地被忽略。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.