AWS*_*per 3 amazon-web-services amazon-iam aws-lambda aws-step-functions
我在账户 A 中有 Step Function,在账户 B 中有 lambda。但是在运行 step 函数时,它给出:
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.
Run Code Online (Sandbox Code Playgroud)
有什么办法可以实现这种配置。
AWS 最终支持基于假设角色的跨账户调用。
AWS Step Functions 不能(直接)调用不同账户中的 AWS Lambda 函数。
一种解决方法是调用 Lambda 函数,该函数调用AssumeRole()账户 B 中的 IAM 角色,然后使用返回的凭证调用账户 B 中的 Lambda 函数。
或者,使用账户 B 中的 API 网关以允许从外部源触发 Lambda 函数。
我们可以在 Step Function 中做这样的事情:
Parameters": {
"FunctionName": "FUNCTION_ARN",
"Payload.$": "$"
},
"Resource": "arn:aws:states:::lambda:invoke"
Run Code Online (Sandbox Code Playgroud)
在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"
}
]
}
Run Code Online (Sandbox Code Playgroud)