【发布时间】:2018-05-21 05:16:06
【问题描述】:
所以我设置了一个 step 函数来调用将发送电子邮件的 Lamba。
我已经手动测试过它并且它可以工作......现在我想用一个新的 lambda 最初调用这个 step 函数......我在网上找到了一些代码,我已经玩过了......通过了测试并且没有引发任何错误....有谁知道我缺少什么,因为它不起作用?
我在https://www.youtube.com/watch?v=9MKL5Jr2zZ4&t=306s上找到了教程中的代码,我认为直接复制它应该没问题,因为她唯一的用途是调用一个步进函数。
谢谢
'use strict';
const AWS = require('aws-sdk');
const stepFunctions = new AWS.StepFunctions();
//module.exports.hello = (event, context, callback) => {
exports.handler = function(event, context) {
const response = {
statusCode:200,
body: JSON.stringify({
message: 'Hello World!',
input: event,
}),
};
// callback(null, response);
};
module.exports.init = (event, context, callback) => {
const params = {
stateMachineArn: 'STATE-MACHINE-ARN',
input: '',
name: 'Execution lambda'
}
stepFunctions.startExecution(params, (err, data) => {
if(err) {
console.log(err);
const response = {
statusCode: 500,
body:JSON.stringify({
message: 'There was an error'
}),
};
callback(null, response);
} else {
console.log(data);
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Step function worked'
})
};
callback(null, response);
}
});
};
我想要这个 lambda 做的就是调用 step 函数 executeSendEmailLambda
任何帮助都会非常感谢
更新 多亏了我的帮助,我想我更近了一点,但我们又回到了测试通过的第一方,但是 lambda 没有调用步骤 F
console.log('Loading function');
const AWS = require('aws-sdk');
exports.handler = function(event, context) {
console.log('Loading step functions');
const stepFunctions = new AWS.StepFunctions({
region: 'US West (Oregon)'
});
console.log('Loading init');
module.exports.init = (event, context, callback) => {
console.log('Loading params');
const params = {
stateMachineArn: 'STATE-MACHINE-ARN',
// input: JSON.stringify({}), Optional if your statemachine requires an application/json input, make sure its stringified
name: 'TestExecution' // name can be anything you want, but it should change for every execution
};
console.log('start step functions');
stepFunctions.startExecution(params, (err, data) => {
if (err) {
console.log(err);
const response = {
statusCode: 500,
body: JSON.stringify({
message: 'There was an error'
})
};
callback(null, response);
} else {
console.log(data);
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Step function worked'
})
};
callback(null, response);
console.log(response);
}
});
};
};
此日志显示以下内容
23:54:47
2017-12-07T23:54:47.448Z 016133fa-dbaa-11e7-8473-7147adf52922 Loading function
23:54:47
START RequestId: 016133fa-dbaa-11e7-8473-7147adf52922 Version: $LATEST
23:54:47
2017-12-07T23:54:47.767Z 016133fa-dbaa-11e7-8473-7147adf52922 Loading step functions
23:54:47
2017-12-07T23:54:47.905Z 016133fa-dbaa-11e7-8473-7147adf52922 Loading init
23:54:47
END RequestId: 016133fa-dbaa-11e7-8473-7147adf52922
23:54:47
REPORT RequestId: 016133fa-dbaa-11e7-8473-7147adf52922 Duration: 178.97 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 31 MB
No newer events found at the moment. Retry.
【问题讨论】:
-
您找到解决方案了吗?我试过你的更新部分代码,lambda执行成功,但它没有调用step函数。
-
看看这里How to call a step funtion from Node.js Lambda function?。我做了同样的事情,从 lambda 调用一个阶跃函数。
标签: javascript node.js amazon-web-services amazon-s3 aws-lambda