Skip to content

Commit

Permalink
Implement pipe for sqs -> sns
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed Nov 27, 2024
1 parent dcefdc1 commit 76e1fe5
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions cdk/quiz_app/quiz_app_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
custom_resources as cr,
CfnOutput as Output,
)
from constructs import Construct
from constructs import Construct, ConstructOrder


class QuizAppStack(Stack):
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
write_capacity=5,
)

dlq_submission_queue = sqs.Queue(self, "QuizSubmissionQueueDLQ")
dlq_submission_queue = sqs.Queue(self, "QuizSubmissionDLQ")
submission_queue = sqs.Queue(
self,
"QuizSubmissionQueue",
Expand Down Expand Up @@ -214,6 +214,48 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
)
)

# eventbridge pipe
policy_document = iam.PolicyDocument.from_json(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
],
"Resource": dlq_submission_queue.queue_arn,
},
{
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": dlq_alarm_topic.topic_arn,
},
],
}
)
policy = iam.ManagedPolicy(
self,
"PipesPolicy",
document=policy_document,
)
pipes_role = iam.Role(
self,
f"PipeRole",
assumed_by=iam.ServicePrincipal("pipes.amazonaws.com"),
managed_policies=[policy],
)
pipe = pipes.CfnPipe(
self,
"DLQToSNSPipe",
source=dlq_submission_queue.queue_arn,
target=dlq_alarm_topic.topic_arn,
role_arn=pipes_role.role_arn,
)

@staticmethod
def read_policy_file(file_path: str) -> dict:
"""Reads a JSON policy file and returns it as a dictionary."""
Expand Down

0 comments on commit 76e1fe5

Please sign in to comment.