委托人 states.amazonaws.com 无权承担所提供的角色
principal states.amazonaws.com is not authorized to assume the provided role
我使用 Terraform 创建了一个 AWS 步函数。目前,step 函数目前只有 1 个 lambda 函数:
resource "aws_iam_role_policy" "sfn_policy" {
policy = jsonencode(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "*"
},
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction",
"lambda:InvokeAsync"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [ "states:StartExecution" ],
"Resource": "*"
}
]
}
)
role = aws_iam_role.processing_lambda_role.id
}
resource "aws_sfn_state_machine" "sfn_state_machine_zip_files" {
name = local.zip_files_step_function_name
role_arn = aws_iam_role.processing_lambda_role.arn
definition = <<EOF
{
"Comment": "Process Incoming Zip Files",
"StartAt": "ProcessIncomingZipFiles",
"States": {
"ProcessIncomingZipFiles": {
"Type": "Task",
"Resource": "${aws_lambda_function.process_zip_files_lambda.arn}",
"ResultPath": "$.Output",
"End": true
}
}
}
EOF
}
角色最初是这样定义的:
resource "aws_iam_role" "processing_lambda_role" {
name = local.name
path = "/service-role/"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = { Service = "lambda.amazonaws.com" }
Action = "sts:AssumeRole"
}
]
})
}
即使策略已经包含 AssumeRole 策略,为什么我会收到此错误消息。我也尝试删除其中一项 sts:AssumeRole
政策,但错误仍然存在。
"Neither the global service principal states.amazonaws.com, nor the regional one is authorized to assume the provided role."
AWS 文档参考:https://aws.amazon.com/premiumsupport/knowledge-center/step-functions-iam-role-troubleshooting/
aws_iam_role.processing_lambda_role
角色只能由 lambda 函数承担。所以,你的 aws_sfn_state_machine.sfn_state_machine_zip_files
不能承担这个角色。您必须将角色中的 Principal
更改为:
Principal = { Service = "lambda.amazonaws.com" }
进入
Principal = { Service = "states.amazonaws.com" }
您可能还有其他问题,具体取决于您要执行的操作。但是你报告的错误是由于我提到的。
我使用 Terraform 创建了一个 AWS 步函数。目前,step 函数目前只有 1 个 lambda 函数:
resource "aws_iam_role_policy" "sfn_policy" {
policy = jsonencode(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "*"
},
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction",
"lambda:InvokeAsync"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [ "states:StartExecution" ],
"Resource": "*"
}
]
}
)
role = aws_iam_role.processing_lambda_role.id
}
resource "aws_sfn_state_machine" "sfn_state_machine_zip_files" {
name = local.zip_files_step_function_name
role_arn = aws_iam_role.processing_lambda_role.arn
definition = <<EOF
{
"Comment": "Process Incoming Zip Files",
"StartAt": "ProcessIncomingZipFiles",
"States": {
"ProcessIncomingZipFiles": {
"Type": "Task",
"Resource": "${aws_lambda_function.process_zip_files_lambda.arn}",
"ResultPath": "$.Output",
"End": true
}
}
}
EOF
}
角色最初是这样定义的:
resource "aws_iam_role" "processing_lambda_role" {
name = local.name
path = "/service-role/"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = { Service = "lambda.amazonaws.com" }
Action = "sts:AssumeRole"
}
]
})
}
即使策略已经包含 AssumeRole 策略,为什么我会收到此错误消息。我也尝试删除其中一项 sts:AssumeRole
政策,但错误仍然存在。
"Neither the global service principal states.amazonaws.com, nor the regional one is authorized to assume the provided role."
AWS 文档参考:https://aws.amazon.com/premiumsupport/knowledge-center/step-functions-iam-role-troubleshooting/
aws_iam_role.processing_lambda_role
角色只能由 lambda 函数承担。所以,你的 aws_sfn_state_machine.sfn_state_machine_zip_files
不能承担这个角色。您必须将角色中的 Principal
更改为:
Principal = { Service = "lambda.amazonaws.com" }
进入
Principal = { Service = "states.amazonaws.com" }
您可能还有其他问题,具体取决于您要执行的操作。但是你报告的错误是由于我提到的。