Getting error when trying to configure SNS with AWS Cognito

I am trying to create a Cognito User Pool and I want it to be able to publish to an sns topic to send SMS messages. My main problem is that when I am trying to bound the resources on the sns topic policy document I am getting this error

Error: creating Cognito User Pool (my-user-pool): InvalidSmsRoleAccessPolicyException: Role does not have permission to publish with SNS

I am not very familiar with AWS and Terraform though so I am providing my configuration in case I’ve missed anything else.

resource "aws_cognito_user_pool" "my_user_pool" {
    name = "my-user-pool"

    password_policy {
      minimum_length                   = 8
      require_lowercase                = true
      require_uppercase                = true
      require_numbers                  = true
      require_symbols                  = false
      temporary_password_validity_days = 7
  }

    admin_create_user_config {
      allow_admin_create_user_only = true
    }

    auto_verified_attributes = ["phone_number"]
    mfa_configuration        = "OPTIONAL"

    software_token_mfa_configuration {
      enabled = true
    }

    sms_configuration {
      external_id    = local.cognito_my_sms_role_ext_id
      sns_caller_arn = aws_iam_role.my_cognito_sms_sender.arn
    }

    lifecycle {
      prevent_destroy = true
    }
  }

  resource "aws_cognito_user_pool_client" "my_cognito_client" {
    name                    = "my-cognito-client"
    user_pool_id            = aws_cognito_user_pool.my_user_pool.id
    generate_secret         = false
    explicit_auth_flows     = ["ALLOW_ADMIN_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"]
    enable_token_revocation = true
  }

  resource "aws_sns_topic" "my_update" {
    name              = "my_update"
    kms_master_key_id = "alias/aws/sns"
    delivery_policy   = file("sns_delivery_policy.json")
  }

  data "aws_iam_role" "my_service" {
    name = "my-service-eks-assume"
  }

  resource "aws_iam_role_policy_attachment" "my_cognito_user_access_attachment" {
    policy_arn = aws_iam_policy.my_cognito_access_policy.arn
    role       = data.aws_iam_role.my_credentials_manager.name
  }

  resource "aws_iam_policy" "my_cognito_access_policy" {
    name        = "my-cognito-access-policy"
    description = "Custom IAM policy for restricting Cognito actions"
    policy      = data.aws_iam_policy_document.my_cognito_access_policy_document.json
  }

  data "aws_iam_policy_document" "my_cognito_access_policy_document" {
    statement {
      actions = [
        "cognito-idp:AdminInitiateAuth",
        "cognito-idp:DescribeUserPoolClient",
        "cognito-idp:AdminUserGlobalSignOut",
        "cognito-idp:AdminCreateUser",
        "cognito-idp:AdminSetUserPassword",
        "cognito-idp:AdminUpdateUserAttributes",
        "cognito-idp:DescribeUserPoolClient",
        "cognito-idp:AdminGetUser",
        "cognito-idp:AdminDisableUser",
        "cognito-idp:AdminEnableUser",
        "cognito-idp:AdminDeleteUser",
        "cognito-idp:ListUsers",
        "cognito-idp:AdminSetUserMFAPreference",
      ]

      resources = ["arn:aws:cognito-idp:${var.aws_region}:${var.aws_account_id}:userpool/${aws_cognito_user_pool.my_user_pool.id}"]
    }
  }

  data "aws_iam_policy_document" "my_cognito_assume_role_policy" {
    statement {
      actions = ["sts:AssumeRole"]

      principals {
        type        = "Service"
        identifiers = ["cognito-idp.amazonaws.com"]
      }
    }
  }

  resource "aws_iam_role" "my_cognito_sms_sender" {
    name               = "my-cognito-sms-sender"
    description        = "Permissions to send SMS messages"
    assume_role_policy = data.aws_iam_policy_document.my_cognito_assume_role_policy.json
  }

  resource "aws_iam_policy" "my_sns_publish_policy" {
    name   = "my-cognito-sns-publish-policy"
    policy = data.aws_iam_policy_document.my_update_sns_topic_policy.json
    tags   = local.tags
  }

  resource "aws_iam_role_policy_attachment" "my_cognito_sns_publish_policy" {
    role       = aws_iam_role.my_cognito_sms_sender.name
    policy_arn = aws_iam_policy.my_sns_publish_policy.arn
  }

  data "aws_iam_policy_document" "my_update_sns_topic_policy" {
    statement {
      actions   = ["sns:Publish"]
      resources = [aws_sns_topic.my_update.arn]

      principals {
        type        = "AWS"
        identifiers = [aws_cognito_user_pool.my_user_pool.arn]
      }
    }
}

If I do this instead:

ata "aws_iam_policy_document" "my_update_sns_topic_policy" {
    statement {
      actions   = ["sns:Publish"]
      resources = ["*"]

      principals {
        type        = "AWS"
        identifiers = [aws_cognito_user_pool.my_user_pool.arn]
      }
  }

I don’t get an error but it is required not to use “*” and be more restrictive.

I have tried multiple configurations the last couple of days, but it seems that it only work using an asterisk in resources.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật