Skip to content

Commit dd26405

Browse files
committed
Removed custom event bus
1 parent 6223ec0 commit dd26405

File tree

9 files changed

+15
-38
lines changed

9 files changed

+15
-38
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ $ saw watch /aws/lambda/events_debug_logger_ec2 --expand
105105
|------|-------------|
106106
| cloudwatch\_log\_group\_arn | ARN of cloudwatch log group which holds service-specific log events. |
107107
| cloudwatch\_log\_group\_name | Name of cloudwatch log group which holds service-specific log events. |
108-
| event\_bus\_arn | ARN of the event bridge eventbus. |
109-
| event\_bus\_name | Name of the event bridge eventbus. |
110108
| event\_rule\_arn | ARN of the event bridge rule. |
111109
| event\_rule\_id | ID of the event bridge rule. |
112110
| event\_rule\_name | Name of the event bridge rule. |

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.16
55
require (
66
github.com/aws/aws-lambda-go v1.23.0
77
github.com/aws/aws-sdk-go v1.27.1
8+
github.com/aws/aws-sdk-go-v2 v1.3.2
89
github.com/aws/aws-sdk-go-v2/config v1.1.6
910
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.3.1
1011
github.com/gruntwork-io/terratest v0.33.0

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
251251
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o=
252252
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s=
253253
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
254-
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
255254
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
256255
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
257256
github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8=

locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ locals {
22
service_name = replace(var.service_name, "-", "_")
33

44
lambdas = {
5-
events_debug_logger = {
5+
events_logger = {
66
description = "Logs eventbridge events for ${var.service_name}."
77
timeout = 10
88
}

outputs.tf

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
output "cloudwatch_log_group_arn" {
22
description = "ARN of cloudwatch log group which holds service-specific log events."
3-
value = aws_cloudwatch_log_group.this["events_debug_logger"].arn
3+
value = aws_cloudwatch_log_group.this["events_logger"].arn
44
}
55

66
output "cloudwatch_log_group_name" {
77
description = "Name of cloudwatch log group which holds service-specific log events."
8-
value = aws_cloudwatch_log_group.this["events_debug_logger"].name
9-
}
10-
11-
output "event_bus_arn" {
12-
description = "ARN of the event bridge eventbus."
13-
value = aws_cloudwatch_event_bus.this.arn
14-
}
15-
16-
output "event_bus_name" {
17-
description = "Name of the event bridge eventbus."
18-
value = aws_cloudwatch_event_bus.this.name
8+
value = aws_cloudwatch_log_group.this["events_logger"].name
199
}
2010

2111
output "event_rule_arn" {

r_cloudwatch.tf

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,16 @@ resource "aws_cloudwatch_log_group" "this" {
66
tags = var.tags
77
}
88

9-
resource "aws_cloudwatch_event_bus" "this" {
10-
name = "${var.name}_${local.service_name}"
11-
tags = var.tags
12-
}
13-
149
resource "aws_cloudwatch_event_rule" "this" {
15-
name = "${var.name}_${local.service_name}_star_rule"
16-
description = "Capture all ${var.service_name} events"
17-
event_bus_name = aws_cloudwatch_event_bus.this.name
18-
19-
event_pattern = jsonencode({
20-
"source" : ["aws.${var.service_name}"],
21-
})
22-
23-
tags = var.tags
10+
name = "${var.name}_${local.service_name}_star_rule"
11+
description = "Capture all ${var.service_name} events"
12+
event_pattern = jsonencode({ "source" : ["aws.${var.service_name}"] })
13+
tags = var.tags
2414
}
2515

2616
resource "aws_cloudwatch_event_target" "this" {
27-
event_bus_name = aws_cloudwatch_event_bus.this.id
28-
arn = aws_lambda_function.this["events_debug_logger"].arn
29-
rule = aws_cloudwatch_event_rule.this.name
17+
arn = aws_lambda_function.this["events_logger"].arn
18+
rule = aws_cloudwatch_event_rule.this.id
3019

3120
retry_policy {
3221
maximum_event_age_in_seconds = 300

r_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "aws_lambda_function" "this" {
3636
resource "aws_lambda_permission" "this" {
3737
action = "lambda:InvokeFunction"
3838
statement_id = "AllowExecutionFromEvents-${join("", [for word in split("_", local.service_name) : title(word)])}"
39-
function_name = aws_lambda_function.this["events_debug_logger"].function_name
39+
function_name = aws_lambda_function.this["events_logger"].function_name
4040
principal = "events.amazonaws.com"
4141
source_arn = aws_cloudwatch_event_rule.this.arn
4242
}

test/complete_invocation_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"strings"
88
"testing"
99

10+
"github.com/aws/aws-sdk-go-v2/aws"
1011
"github.com/aws/aws-sdk-go-v2/config"
1112
"github.com/aws/aws-sdk-go-v2/service/eventbridge"
1213
"github.com/aws/aws-sdk-go-v2/service/eventbridge/types"
13-
"github.com/aws/aws-sdk-go/aws"
1414
"github.com/aws/aws-sdk-go/aws/awserr"
1515
"github.com/gruntwork-io/terratest/modules/random"
1616
"github.com/gruntwork-io/terratest/modules/terraform"
@@ -19,6 +19,7 @@ import (
1919

2020
func TestCompleteInvocation(t *testing.T) {
2121
t.Parallel()
22+
name := "events_logger"
2223
uniqueID := strings.ToLower(random.UniqueId())
2324
serviceName := "ecs"
2425

@@ -40,8 +41,7 @@ func TestCompleteInvocation(t *testing.T) {
4041

4142
client := eventbridge.NewFromConfig(cfg)
4243
input := &eventbridge.DescribeRuleInput{
43-
Name: aws.String(fmt.Sprintf("_%s_%s_star_rule", uniqueID, serviceName)),
44-
EventBusName: aws.String(fmt.Sprintf("_%s_%s", uniqueID, serviceName)),
44+
Name: aws.String(fmt.Sprintf("_%s_%s_star_rule", uniqueID, serviceName)),
4545
}
4646

4747
response, err := client.DescribeRule(context.TODO(), input)
@@ -53,7 +53,7 @@ func TestCompleteInvocation(t *testing.T) {
5353
}
5454
}
5555

56-
expectedSawCommand := fmt.Sprintf("saw watch /aws/lambda/events_debug_logger_%s --expand", serviceName)
56+
expectedSawCommand := fmt.Sprintf("saw watch /aws/lambda/%s_%s --expand", name, serviceName)
5757
sawCommand := terraform.Output(t, options, "saw_command")
5858

5959
assert.Equal(t, expectedSawCommand, sawCommand)

0 commit comments

Comments
 (0)