-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* change file name * add sqs and variables * update variable names * instance key and && operator * add event target bus name * allow lambda messages from sqs * add vars and outputs * use arn instead of id * just use name * propagate outputs * rewmove lambda var * add lambda permission and change to arn * ensure queue visibility timeout aligns * correct ecr * stop pipeline pass on failed preprod plan * update lambda to allow execute from sqs * explicitly declare resource * add sqs queue policy resource * allow lambda decrypt permissions * remove condition * rename kms * allow permissions on kms key * temporarily comment kms * enable kms cmk * update kms vars * remove duplicated key * add cmk * conditionally create resources in upper environments * conditionally create resources * remove old kms * use correct kms key * allow describe key on lambda role * allow decrypt on * * try specific target key arn * update account ids
- Loading branch information
1 parent
d394448
commit 965911e
Showing
18 changed files
with
289 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
func Handler(ctx context.Context) (string, error) { | ||
fmt.Println("Hello World") | ||
return "Hello World!", nil | ||
func handler(event events.SQSEvent) error { | ||
for _, record := range event.Records { | ||
err := processMessage(record) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
fmt.Println("done") | ||
return nil | ||
} | ||
|
||
func processMessage(record events.SQSMessage) error { | ||
fmt.Printf("Processed message %s\n", record.Body) | ||
fmt.Printf("Hello, world!\n") | ||
return nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(Handler) | ||
lambda.Start(handler) | ||
fmt.Printf("Hello, world!\n") | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
resource "aws_cloudwatch_event_bus" "main" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = var.environment_name | ||
provider = aws.region | ||
} | ||
|
||
resource "aws_cloudwatch_event_archive" "main" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = var.environment_name | ||
event_source_arn = aws_cloudwatch_event_bus.main[0].arn | ||
provider = aws.region | ||
} | ||
|
||
resource "aws_cloudwatch_event_rule" "receive_events_from_mlpa" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
name = "${var.environment_name}-mlpa-events-to-use" | ||
description = "Receive events from mlpa" | ||
event_bus_name = aws_cloudwatch_event_bus.main[0].name | ||
|
||
event_pattern = jsonencode({ | ||
source = ["opg.poas.makeregister"], | ||
detail-type = ["lpa-access-granted"] | ||
}) | ||
|
||
provider = aws.region | ||
} | ||
|
||
resource "aws_cloudwatch_event_bus_policy" "cross_account_receive" { | ||
count = length(var.receive_account_ids) > 0 && var.event_bus_enabled ? 1 : 0 | ||
event_bus_name = aws_cloudwatch_event_bus.main[0].name | ||
policy = data.aws_iam_policy_document.cross_account_receive[0].json | ||
provider = aws.region | ||
} | ||
|
||
# Allow MLPA account to send messages | ||
data "aws_iam_policy_document" "cross_account_receive" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
statement { | ||
sid = "CrossAccountAccess" | ||
effect = "Allow" | ||
actions = [ | ||
"events:PutEvents", | ||
] | ||
resources = [ | ||
aws_cloudwatch_event_bus.main[0].arn | ||
] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = var.receive_account_ids | ||
} | ||
} | ||
} | ||
|
||
resource "aws_cloudwatch_event_target" "receive_events" { | ||
count = var.event_bus_enabled ? 1 : 0 | ||
rule = aws_cloudwatch_event_rule.receive_events_from_mlpa[0].name | ||
arn = aws_sqs_queue.receive_events_queue[0].arn | ||
event_bus_name = aws_cloudwatch_event_bus.main[0].name | ||
dead_letter_config { | ||
arn = aws_sqs_queue.receive_events_deadletter[0].arn | ||
} | ||
|
||
provider = aws.region | ||
} |
Oops, something went wrong.