forked from terraform-aws-modules/terraform-aws-eventbridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Added example of scheduled events with lambda functions (terra…
- Loading branch information
1 parent
cc66f74
commit 452c21e
Showing
10 changed files
with
279 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ terraform { | |
required_providers { | ||
aws = ">= 3.19" | ||
random = ">= 3" | ||
null = ">= 2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# EventBridge Lambda & Scheduled Events Example | ||
|
||
Configuration in this directory creates EventBridge resource configuration including an Lambda service. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.19 | | ||
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_null"></a> [null](#provider\_null) | >= 2 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_eventbridge"></a> [eventbridge](#module\_eventbridge) | ../../ | | | ||
| <a name="module_lambda"></a> [lambda](#module\_lambda) | terraform-aws-modules/lambda/aws | ~> 2.0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_eventbridge_rule_arns"></a> [eventbridge\_rule\_arns](#output\_eventbridge\_rule\_arns) | The EventBridge Rule ARNs | | ||
| <a name="output_lambda_function_arn"></a> [lambda\_function\_arn](#output\_lambda\_function\_arn) | The ARN of the Lambda Function | | ||
| <a name="output_lambda_function_name"></a> [lambda\_function\_name](#output\_lambda\_function\_name) | The name of the Lambda Function | | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
provider "aws" { | ||
region = "ap-southeast-1" | ||
|
||
# Make it faster by skipping something | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
} | ||
|
||
module "eventbridge" { | ||
source = "../../" | ||
|
||
create_bus = false | ||
|
||
rules = { | ||
crons = { | ||
description = "Trigger for a Lambda" | ||
schedule_expression = "rate(5 minutes)" | ||
} | ||
} | ||
|
||
targets = { | ||
crons = [ | ||
{ | ||
name = "lambda-loves-cron" | ||
arn = module.lambda.lambda_function_arn | ||
input = jsonencode({ "job" : "cron-by-rate" }) | ||
} | ||
] | ||
} | ||
} | ||
|
||
################## | ||
# Extra resources | ||
################## | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
############################################# | ||
# Using packaged function from Lambda module | ||
############################################# | ||
|
||
module "lambda" { | ||
source = "terraform-aws-modules/lambda/aws" | ||
version = "~> 2.0" | ||
|
||
function_name = "${random_pet.this.id}-lambda" | ||
handler = "index.lambda_handler" | ||
runtime = "python3.8" | ||
|
||
create_package = false | ||
local_existing_package = local.downloaded | ||
|
||
create_current_version_allowed_triggers = false | ||
allowed_triggers = { | ||
ScanAmiRule = { | ||
principal = "events.amazonaws.com" | ||
source_arn = module.eventbridge.eventbridge_rule_arns["crons"] | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
package_url = "https://raw.githubusercontent.com/terraform-aws-modules/terraform-aws-lambda/master/examples/fixtures/python3.8-zip/existing_package.zip" | ||
downloaded = "downloaded_package_${md5(local.package_url)}.zip" | ||
} | ||
|
||
resource "null_resource" "download_package" { | ||
triggers = { | ||
downloaded = local.downloaded | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = "curl -L -o ${local.downloaded} ${local.package_url}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "eventbridge_rule_arns" { | ||
description = "The EventBridge Rule ARNs" | ||
value = module.eventbridge.eventbridge_rule_arns | ||
} | ||
|
||
output "lambda_function_arn" { | ||
description = "The ARN of the Lambda Function" | ||
value = module.lambda.lambda_function_arn | ||
} | ||
|
||
output "lambda_function_name" { | ||
description = "The name of the Lambda Function" | ||
value = module.lambda.lambda_function_name | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = ">= 3.19" | ||
random = ">= 2" | ||
null = ">= 2" | ||
} | ||
} |