From 3d63614d5f8360d305a7fa8e9e094d2268e53cb1 Mon Sep 17 00:00:00 2001 From: Moritz Zimmer Date: Tue, 11 Feb 2020 10:20:51 +0100 Subject: [PATCH] support for cloudwatch event pattern as trigger unified existing support of scheduled events with new pattern based event trigger in new submodule **this needs to be released as new major v5 version** fixes #53 --- README.md | 6 +-- .../README.md | 4 +- .../example-with-cloudwatch-event/main.tf | 37 ++++++++++++++ .../test_function.zip | 0 .../versions.tf | 0 .../main.tf | 27 ---------- main.tf | 11 +++-- .../main.tf | 5 ++ modules/event/cloudwatch-event/variables.tf | 49 +++++++++++++++++++ .../versions.tf | 0 .../cloudwatch-scheduled-event/variables.tf | 14 ------ 11 files changed, 104 insertions(+), 49 deletions(-) rename examples/{example-with-cloudwatch-scheduled-event => example-with-cloudwatch-event}/README.md (73%) create mode 100644 examples/example-with-cloudwatch-event/main.tf rename examples/{example-with-cloudwatch-scheduled-event => example-with-cloudwatch-event}/test_function.zip (100%) rename examples/{example-with-cloudwatch-scheduled-event => example-with-cloudwatch-event}/versions.tf (100%) delete mode 100644 examples/example-with-cloudwatch-scheduled-event/main.tf rename modules/event/{cloudwatch-scheduled-event => cloudwatch-event}/main.tf (76%) create mode 100644 modules/event/cloudwatch-event/variables.tf rename modules/event/{cloudwatch-scheduled-event => cloudwatch-event}/versions.tf (100%) delete mode 100644 modules/event/cloudwatch-scheduled-event/variables.tf diff --git a/README.md b/README.md index c5943fd..aa93721 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Terraform module to create AWS [Lambda](https://www.terraform.io/docs/providers/ The following [event sources](https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html) are supported (see [examples](#examples)): -- [cloudwatch-scheduled-event](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-cloudwatch-scheduled-event): configures a [CloudWatch Event Rule](https://www.terraform.io/docs/providers/aws/r/cloudwatch_event_rule.html) to trigger the Lambda on a regular, scheduled basis +- [cloudwatch-event](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-cloudwatch-event): configures a [CloudWatch Event Rule](https://www.terraform.io/docs/providers/aws/r/cloudwatch_event_rule.html) to trigger the Lambda by CloudWatch [event pattern](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html) or on a regular, scheduled basis - [dynamodb](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-dynamodb-event): configures an [Event Source Mapping](https://www.terraform.io/docs/providers/aws/r/lambda_event_source_mapping.html) to trigger the Lambda by DynamoDb events - [kinesis](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-kinesis-event): configures an [Event Source Mapping](https://www.terraform.io/docs/providers/aws/r/lambda_event_source_mapping.html) to trigger the Lambda by Kinesis events - [s3](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-s3-event): configures permission to trigger the Lambda by S3 @@ -46,7 +46,7 @@ module "lambda" { // configurable event trigger, see examples event = { - type = "cloudwatch-scheduled-event" + type = "cloudwatch-event" schedule_expression = "rate(1 minute)" } @@ -74,7 +74,7 @@ module "lambda" { ### Examples -- [example-with-cloudwatch-scheduled-event](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-cloudwatch-scheduled-event) +- [example-with-cloudwatch-event](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-cloudwatch-event) - [example-with-dynamodb-event](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-dynamodb-event) - [example-with-kinesis-event](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-kinesis-event) - [example-with-s3-event](https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-s3-event) diff --git a/examples/example-with-cloudwatch-scheduled-event/README.md b/examples/example-with-cloudwatch-event/README.md similarity index 73% rename from examples/example-with-cloudwatch-scheduled-event/README.md rename to examples/example-with-cloudwatch-event/README.md index c8d14be..77a08d9 100644 --- a/examples/example-with-cloudwatch-scheduled-event/README.md +++ b/examples/example-with-cloudwatch-event/README.md @@ -1,6 +1,6 @@ -# Example with CloudWatch scheduled event +# Example with CloudWatch events -Creates an AWS Lambda function triggered by a CloudWatch (scheduled) [event](https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html). +Creates AWS Lambda functions triggered by a CloudWatch [events](https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html). ## requirements diff --git a/examples/example-with-cloudwatch-event/main.tf b/examples/example-with-cloudwatch-event/main.tf new file mode 100644 index 0000000..eeb27ea --- /dev/null +++ b/examples/example-with-cloudwatch-event/main.tf @@ -0,0 +1,37 @@ +provider "aws" { + region = "eu-west-1" +} + +module "lambda-scheduled" { + source = "../../" + description = "Example AWS Lambda using go with cloudwatch scheduled event trigger" + filename = "${path.module}/test_function.zip" + function_name = "tf-example-go-basic" + handler = "example-lambda-func" + runtime = "go1.x" + + event = { + type = "cloudwatch-event" + schedule_expression = "rate(1 minute)" + } +} + +module "lambda-pattern" { + source = "../../" + description = "Example AWS Lambda using go with cloudwatch event pattern trigger" + filename = "${path.module}/test_function.zip" + function_name = "tf-example-go-basic" + handler = "example-lambda-func" + runtime = "go1.x" + + event = { + type = "cloudwatch-event" + event_pattern = <