-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forwarder): allow specifying EventBridge pattern
This commit allows users to configure a more specific eventbridge pattern to trigger the forwarder lambda. This can be useful when attempting to subscribe only a subset of objects, and additionally provides a mechanism to disable eventbridge outright.
- Loading branch information
Showing
9 changed files
with
158 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Forwarding a subset of S3 files via EventBridge | ||
|
||
This module demonstrates how to forward a subset of objects from an S3 bucket | ||
which send bucket notifications to EventBridge. | ||
|
||
To run this example you need to execute: | ||
|
||
``` | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
After applying, you can copy files to the source bucket, and verify if they are written to the destination: | ||
|
||
``` | ||
aws s3 cp ./main.tf s3://`terraform output -raw source_bucket`/a/foo/main.tf | ||
aws s3 cp ./main.tf s3://`terraform output -raw source_bucket`/a/bar/main.tf | ||
aws s3 cp ./main.tf s3://`terraform output -raw source_bucket`/a/baz/main.tf | ||
... | ||
aws s3 ls `terraform output -raw destination_bucket`/a/ | ||
PRE bar/ | ||
PRE foo/ | ||
``` | ||
|
||
Note that this example may create resources which can 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) | >= 1.3 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 | | ||
| <a name="requirement_observe"></a> [observe](#requirement\_observe) | ~> 0.14 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_forwarder"></a> [forwarder](#module\_forwarder) | ../..//modules/forwarder | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_s3_bucket.destination](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | | ||
| [aws_s3_bucket.source](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | | ||
| [aws_s3_bucket_notification.source](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_notification) | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_destination_bucket"></a> [destination\_bucket](#output\_destination\_bucket) | Destination bucket name to read objects from. | | ||
| <a name="output_source_bucket"></a> [source\_bucket](#output\_source\_bucket) | Source bucket name to write objects to. | | ||
<!-- 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,41 @@ | ||
locals { | ||
name = basename(abspath(path.root)) | ||
name_prefix = "${local.name}-" | ||
} | ||
|
||
resource "aws_s3_bucket" "source" { | ||
bucket_prefix = "${local.name_prefix}src-" | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_s3_bucket_notification" "source" { | ||
bucket = aws_s3_bucket.source.id | ||
eventbridge = true | ||
} | ||
|
||
resource "aws_s3_bucket" "destination" { | ||
bucket_prefix = "${local.name_prefix}dst-" | ||
force_destroy = true | ||
} | ||
|
||
module "forwarder" { | ||
# Prefer using the hashicorp registry: | ||
# source = "observeinc/collection/aws//modules/forwarder" | ||
# For validation purposes we will instead refer to a local version of the | ||
# module: | ||
source = "../..//modules/forwarder" | ||
name = local.name | ||
|
||
destination = { | ||
bucket = aws_s3_bucket.destination.id | ||
} | ||
|
||
source_bucket_names = [aws_s3_bucket.source.id] | ||
|
||
source_eventbridge_pattern = { | ||
"detail.object.key" = [ | ||
{ "wildcard" = "*/foo/*" }, | ||
{ "wildcard" = "*/bar/*" }, | ||
] | ||
} | ||
} |
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 @@ | ||
output "source_bucket" { | ||
description = "Source bucket name to write objects to." | ||
value = aws_s3_bucket.source.id | ||
} | ||
|
||
output "destination_bucket" { | ||
description = "Destination bucket name to read objects from." | ||
value = aws_s3_bucket.destination.id | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/forwarder-s3-eventbridge-pattern/tests/example.tftest.hcl
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,6 @@ | ||
mock_provider "observe" { | ||
source = "../../modules/testing/observe_mock" | ||
} | ||
|
||
# only verifies module can be installed and removed correctly | ||
run "install" {} |
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,15 @@ | ||
terraform { | ||
required_version = ">= 1.3" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.0" | ||
} | ||
|
||
observe = { | ||
source = "terraform.observeinc.com/observeinc/observe" | ||
version = "~> 0.14" | ||
} | ||
} | ||
} |
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