所以我设置了一个步骤函数来调用将发送电子邮件的兰巴。
我已经手动测试了它并且它有效...现在我想最初使用新的 lambda 调用此步骤函数...我在网上找到了一些代码并且我已经玩过它...通过了测试并且不会引发任何错误......有谁知道我错过了什么,因为它不起作用?
我从教程中找到了代码https://www.youtube.com/watch?v=9MKL5Jr2zZ4&t=306s
我认为直接复制它应该可以,因为她唯一的用途是调用步骤函数。
Thanks
'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 做的就是调用步骤函数executeSendEmailLambda
任何帮助将不胜感激,谢谢
UPDATE感谢 的帮助,我想我更接近了一点,但我们又回到了测试通过的第一个阶段,但 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.