我正在尝试从 Node.js lambda 函数调用步骤函数。我尝试了该解决方案并更新了实现thread.
显示错误响应的解决方案,但更新后的代码显示成功响应。但更新后的代码没有调用step函数。
My Code:
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-east-2'
});
console.log('Loading init');
module.exports.init = (event, context, callback) => {
console.log('Loading params');
const params = {
stateMachineArn: 'ARN of My State Machine',
// 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);
}
});
};
};
我已将上述代码添加到 Lambda 函数中并部署代码。之后我使用了 lambda 函数的 Test 选项。这是执行 Lambda 函数的正确方法吗?测试结果是成功的,但是当我检查状态机时,没有最近的执行。帮助我找到解决方案,我对步骤功能非常陌生。提前致谢。
以下是我所做的事情:
- 创建了 lambda 并添加了步骤函数执行的权限
lambda role
- 创建了类型的step函数(只是一个hello world)
standard
。在创作时我选择了ALL Logs
哪个去CloudWatch Log Group
。甚至它们也被展示在step function
控制台如下Logging
tab.
下面是我调用步骤函数的代码:
var aws = require('aws-sdk')
exports.handler = (event, context, callback) => {
var params = {
stateMachineArn: 'arn:aws:states:us-east-1:1234567890:stateMachine:Helloworld',
input: JSON.stringify({})
};
var stepfunctions = new aws.StepFunctions()
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 函数执行日志
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)