在其 lambda 之一(无服务器框架)中获取 Step 函数的执行 arn
Get execution arn of Step function inside one of its lambdas (Serverless Framework)
使用 Serverless 框架和 step function 框架,我可以从 lambda 函数内部获取执行 ARN 吗?
您可以像"Execution.$": "$$.Execution.Id"
一样输出执行ARN。 (doc)
下面是一个带有 Lambda 函数的简单演示。
名称为 HelloFunction 的 Nodejs Lambda 函数(仅用于输出到 CloudWatch 日志):
exports.handler = (event, context, callback) => {
console.log(event);
};
步进函数(只需将 "$$.Execution.Id"
放入 HelloFunction lambda):
{
"Comment": "put execution ARN to Lambda",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "HelloFunction",
"Payload": {
"Execution.$": "$$.Execution.Id"
}
},
"End": true
}
}
}
输出如下:
2021-09-23T00:05:07.197Z xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx INFO {
Execution: 'arn:aws:states:<region>-1:111122223333:execution:MyStateMachine_lambda_callback_service_integration_pattern:xxxxxxxxx-xxxx-xxxxxxxxxxxxx'
}
使用 Serverless 框架和 step function 框架,我可以从 lambda 函数内部获取执行 ARN 吗?
您可以像"Execution.$": "$$.Execution.Id"
一样输出执行ARN。 (doc)
下面是一个带有 Lambda 函数的简单演示。
名称为 HelloFunction 的 Nodejs Lambda 函数(仅用于输出到 CloudWatch 日志):
exports.handler = (event, context, callback) => {
console.log(event);
};
步进函数(只需将 "$$.Execution.Id"
放入 HelloFunction lambda):
{
"Comment": "put execution ARN to Lambda",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "HelloFunction",
"Payload": {
"Execution.$": "$$.Execution.Id"
}
},
"End": true
}
}
}
输出如下:
2021-09-23T00:05:07.197Z xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx INFO {
Execution: 'arn:aws:states:<region>-1:111122223333:execution:MyStateMachine_lambda_callback_service_integration_pattern:xxxxxxxxx-xxxx-xxxxxxxxxxxxx'
}