我已经设置了一个步骤函数来调用lambda发送电子邮件。
我已经进行手动测试,它的确有效...现在我想使用新的lambda最初调用此步骤函数...我已经在网上找到了一些代码,并进行了尝试...通过了测试并且没有触发任何错误...有人知道我缺少什么吗,因为它没有起作用?
我从 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函数只需调用步骤函数executeSendEmailLambda
。
任何帮助都将不胜感激。
更新 在得到I think I am one的帮助后,我们又回到了测试通过但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.