0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TerraformでLambdaのCloudWatchイベントトリガを無効にする

Posted at

Lambda の CloudWatch イベントトリガーを無効にしたい時、コンソールからならここで操作出来ますが、

Screenshot.png

Terraform からどうやるのかと思ったら aws_lambda_permission.action = "lambda:DisableInvokeFunction" にする必要がありました。 enable/disable みたいなスイッチではないので気づきませんでした。
aws_cloudwatch_event_rule.is_enabled ではないので気をつけましょう。


resource "aws_lambda_permission" "allow_to_invoke_func" {
  statement_id  = "AllowExecutionFromCloudWatch"
  function_name = "${aws_lambda_function.func.function_name}"
  principal     = "events.amazonaws.com"
  source_arn    = "${aws_cloudwatch_event_rule.minutely.arn}"

  /* 無効にする場合は "lambda:DisableInvokeFunction" を指定する */
  /* action        = "lambda:InvokeFunction" */
  action        = "lambda:DisableInvokeFunction"
}

resource "aws_cloudwatch_event_rule" "minutely" {
  name                = "minutely"
  schedule_expression = "rate(1 minute)"
}

resource "aws_cloudwatch_event_target" "invoke_func_minutely" {
  rule      = "${aws_cloudwatch_event_rule.minutely.name}"
  target_id = "invoke-func"
  arn       = "${aws_lambda_function.func.arn}"
}

resource "aws_lambda_function" "func" {
  filename         = "${data.archive_file.function_zip.output_path}"
  function_name    = "${var.app_name}-function"
  role             = "${aws_iam_role.lambda_exec.arn}"
  handler          = "index.handler"
  source_code_hash = "${data.archive_file.function_zip.output_base64sha256}"
  runtime          = "ruby2.5"
}
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?