为 awsgluecrawler 设置时间表

问题描述 投票:0回答:1

通过 Terraform 将每日计划添加到 AWS Glue Crawler 的正确方法是什么?我尝试遵循官方文档并尝试了这个:

resource "aws_glue_crawler" "test" {
  name              = "test"
  description       = "Ctest"
  role              = data.aws_iam_role.test.arn
  database_name     = "test"
  schedule          = "cron(0 23 * * *)" 

  schema_change_policy {
    delete_behavior = "LOG"
    update_behavior = "LOG"
  }

  s3_target {
    path        = "s3://test//"
    sample_size = 10
  }

  recrawl_policy {
    recrawl_behavior = "CRAWL_NEW_FOLDERS_ONLY"
  }

  configuration = jsonencode(
    {
      CreatePartitionIndex = true
      Version = 1
    }
  )
}

为什么在应用 terraform 更改时会出现此错误?

Message_:“无效的计划 cron 表达式:cron(0 23 * * *)”

我通过在线工具测试了cron表达式,它似乎是有效的。

amazon-web-services terraform aws-glue terraform-provider-aws
1个回答
0
投票

如果您确实仔细查看了docs,您会发现 cron 表达式与您当前配置中的略有不同。例如,这应该有效:

resource "aws_glue_crawler" "test" {
  name              = "test"
  description       = "Ctest"
  role              = data.aws_iam_role.test.arn
  database_name     = "test"
  schedule          = "cron(0 23 * * ? *)" 

  schema_change_policy {
    delete_behavior = "LOG"
    update_behavior = "LOG"
  }

  s3_target {
    path        = "s3://test//"
    sample_size = 10
  }

  recrawl_policy {
    recrawl_behavior = "CRAWL_NEW_FOLDERS_ONLY"
  }

  configuration = jsonencode(
    {
      CreatePartitionIndex = true
      Version = 1
    }
  )
}

在这种情况下,爬虫会在每天晚上 11 点运行。来自 AWS docs 的 cron 表达式:

cron(分钟小时月日月日年)

如果您不想一周中的每一天都运行该作业,您可以查看 AWS 文档中的示例部分。

© www.soinside.com 2019 - 2024. All rights reserved.