步骤功能的跨帐户Lambda呼叫

问题描述

我在帐户A中具有步进功能,并且在帐户B中具有lambda。但是在运行步进功能时,它给出了:

An error occurred while executing the state 'lambdaB' (entered at the event id #2). The resource belongs to a different account from the running execution.

可以通过任何方式进行此配置。

解决方法

AWS Step Functions无法(直接)在其他帐户中调用AWS Lambda函数。

一种解决方法是调用Lambda函数,该函数在帐户B的IAM角色上调用AssumeRole(),然后使用返回的凭据在帐户B中调用Lambda函数。

或者,使用帐户B中的API网关,以允许从外部源触发Lambda函数。

,

我们可以在“步进功能”中执行以下操作:

Parameters": {
                "FunctionName": "FUNCTION_ARN","Payload.$": "$"
            },"Resource": "arn:aws:states:::lambda:invoke"

在Lambda中,我们需要添加权限:

"Version": "2012-10-17","Id": "default","Statement": [
    {
      "Sid": "sid-1","Effect": "Allow","Principal": {
        "AWS": "arn:aws:iam::ACCOUNT_A:root"
      },"Action": "lambda:InvokeFunction","Resource": "FUNCTION_ARN"
    }
  ]
}
,

我无法投票,因为我没有足够的声望点。我会说 step 函数可以像“AWS_Developer”回答的那样以不同的方式调用 lambda。我们不必使用另一个 lambda 来调用 lambda,只需在 lambda 函数权限设置中赋予 step 函数执行角色权限即可。

以下设置是从 AWS_Developer 复制的:

"Version": "2012-10-17","Principal": {
        "AWS": "arn:aws:iam::ACCOUNT_STEP_FUNCTION:root"
      },"Resource": "FUNCTION_ARN"
    }
  ]
}