Permissions Error with Cross-Account logs sharing to Firehose

0

Hi,

I am sending logs from one account using Subscription Filter to send to a Kinesis Firehose Destination, which is a part of AWS Organizations.

I am able to set up the destination, destination policies (allowing accounts in the organization), and subscription filter.

But, I am getting the error of permission denied while deploying Subscription Filter with Terraform.

Is there anything specific to be done in this case? Any help is appreciated.

Thanks!

1개 답변
1
수락된 답변

Hi Issac,

It seems like the issue is with the permissions related to the Cloudwatch Logs (Subscription Filter) from your source account.

Before that, please make sure you have followed the steps mentioned in this documentation, and correctly configured Source and Destination Accounts: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CrossAccountSubscriptions-Firehose.html

Regarding the permission issue, please check if you have attached the IAM Role to the Subscription Filter, which is required when destination policy has an "Organizational condition".

Try referring to the below sample code, and use it in your Terraform code:

# CloudWatch Log IAM Role and policy (For Subscription Filter)
resource "aws_iam_role" "cwl_role" {
  name = "logfilter-role"
  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = "sts:AssumeRole"
        Effect = "Allow"
        Principal = {
          Service = "logs.amazonaws.com"
        }
      }
    ]
  })
}

resource "aws_iam_policy" "cwl_policy" {
  name = "logfilter-policy"

  policy = jsonencode({
    Version = "2012-10-17",
    Statement = [
      {
        Effect = "Allow",
        Action = "logs:PutLogEvents",
        Resource = [
          "arn:aws:logs:${var.region}:${var.account_id}:log-group:*"
        ]
      }
    ]
  })
}

resource "aws_iam_role_policy_attachment" "cwl_policy_attachment" {
  policy_arn = aws_iam_policy.cwl_policy.arn
  role       = aws_iam_role.cwl_role.name
}


resource "aws_cloudwatch_log_subscription_filter" "cwl_firehose_subsfilter" {
  name            = "logfilter"
  ... ... ...
  role_arn        = aws_iam_role.cwl_role.arn   # Use the role in the subscription filter
}

Please let me know if this solves the issue.

Thanks,

Atul

profile picture
답변함 8달 전
profile pictureAWS
전문가
검토됨 8달 전
profile pictureAWS
전문가
검토됨 8달 전
  • Thanks for your response. It worked like a charm! I couldn't find any document mentioning this as a required configuration for Subscription Filter. But anyways, thank you so much!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠