I want to create a step function that runs a lambda function. These are the policies I have attached to my state machine and role for now:
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"
}
]
})
}
resource "aws_iam_role_policy" "lambda" {
name = local.processing_lambda_permission_name
role = aws_iam_role.processing_lambda_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:ListBucket",
"s3:HeadObject",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:PutObject"
]
Resource = [
aws_s3_bucket.ingest.arn,
"${aws_s3_bucket.ingest.arn}/*",
aws_s3_bucket.dwh.arn,
"${aws_s3_bucket.dwh.arn}/*",
]
},
{
Effect = "Allow"
Action = [
"s3:DeleteObject"
]
Resource = ["${aws_s3_bucket.ingest.arn}/*"]
},
{
Effect = "Allow"
Action = [
"kms:Decrypt",
"kms:GenerateDataKey",
]
# If it breaks because of permission to the s3 buckets, look here
Resource = "*"
#Resource = [aws_kms_key.dwh.arn, aws_kms_key.ingest.arn]
},
]
})
}
Are there any missing policies? Currently, I get this error:
"Neither the global service principal states.amazonaws.com, nor the regional one is authorized to assume the provided role."
I know that the step function does start because I see that it enters the TaskStateEntered
. However, it fails when it comes to running the lambda function.