Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Note in Every command and URL being called there are fields that need to be repl

Example replacements (make sure to replace the curly brackets as well: don't keep curly brackets)

`{studentName}` - example `ajdewilzin` - this can be your name, independent of your login details
`jonashalvorsen` - example `ajdewilzin` - this can be your name, independent of your login details

`{region}` - example `eu-north-1`
`eu-north-1` - example `eu-north-1`

### Steps
1. Create an SNS Topic:

```bash
aws sns create-topic --name {studentName}OrderCreatedTopic
aws sns create-topic --name jonashalvorsenOrderCreatedTopic
```
If successful, you will see in your terminal a JSON response that includes `"TopicArn": "...`.

Expand All @@ -22,7 +22,7 @@ Replace `_topicArn` in your Controller code with the generated `TopicArn` value
2. Create an SQS Queue:

```bash
aws sqs create-queue --queue-name {studentName}OrderQueue
aws sqs create-queue --queue-name jonashalvorsenOrderQueue
```

If successful, you will see in your terminal a JSON response that includes `"QueueUrl": "some_aws_url`.
Expand All @@ -31,21 +31,26 @@ Replace `_queueUrl` in your Controller code with the generated `QueueUrl` from t


```bash
aws sns subscribe --topic-arn arn:aws:sns:{region}:637423341661:{studentName}OrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:{region}:637423341661:{studentName}OrderQueue
aws sns subscribe --topic-arn arn:aws:sns:eu-north-1:637423341661:jonashalvorsenOrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:eu-north-1:637423341661:jonashalvorsenOrderQueue
```

You don't need to save the generated SubscriptionArn.

3. Create an EventBridge Event Bus:

```bash
aws events create-event-bus --name {StudentName}CustomEventBus --region {region}
aws events create-event-bus --name jonashalvorsenCustomEventBus --region eu-north-1
```

4. Create an EventBridge Rule:

```bash
aws events put-rule --name {StudentName}OrderProcessedRule --event-pattern '{\"source\": [\"order.service\"]}' --event-bus-name {StudentName}CustomEventBus
aws events put-rule --name jonashalvorsenOrderProcessedRule --event-pattern '{\"source\": [\"order.service\"]}' --event-bus-name jonashalvorsenCustomEventBus
```

Without \
```bash
aws events put-rule --name jonashalvorsenOrderProcessedRule --event-pattern '{"source": ["order.service"]}' --event-bus-name jonashalvorsenCustomEventBus
```

If your terminal complains about double quotes, you might need to remove the backslash `\` from the command above (and commands later on).
Expand All @@ -54,22 +59,21 @@ If your terminal complains about double quotes, you might need to remove the bac
5. Subscribe the SQS Queue to the SNS Topic

```bash
aws sqs get-queue-attributes --queue-url https://sqs.{region}.amazonaws.com/637423341661/{studentName}OrderQueue --attribute-name QueueArn --region {region}
aws sqs get-queue-attributes --queue-url https://sqs.eu-north-1.amazonaws.com/637423341661/jonashalvorsenOrderQueue --attribute-name QueueArn --region eu-north-1
```

```bash
aws sns subscribe --topic-arn arn:aws:sns:{region}:637423341661:{studentName}OrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:{region}:637423341661:{studentName}OrderQueue --region {region}
aws sns subscribe --topic-arn arn:aws:sns:eu-north-1:637423341661:jonashalvorsenOrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:eu-north-1:637423341661:jonashalvorsenOrderQueue --region eu-north-1
```

6. Grant SNS Permissions to SQS


In Bash/Unix terminals you can run this command:
```bash
aws sqs set-queue-attributes --queue-url https://sqs.{region}.amazonaws.com/637423341661/{studentName}OrderQueue --attributes '{"Policy":"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"SQS:SendMessage\",\"Resource\":\"arn:aws:sqs:{region}:637423341661:{studentName}OrderQueue\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:sns:{region}:637423341661:{studentName}OrderCreatedTopic\"}}}]}"}' --region {region}
aws sqs set-queue-attributes --queue-url https://sqs.eu-north-1.amazonaws.com/637423341661/jonashalvorsenOrderQueue --attributes '{"Policy":"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"SQS:SendMessage\",\"Resource\":\"arn:aws:sqs:eu-north-1:637423341661:jonashalvorsenOrderQueue\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:sns:eu-north-1:637423341661:jonashalvorsenOrderCreatedTopic\"}}}]}"}' --region eu-north-1
```


## Core Exercise
1. Create a few orders using a RDS database. Orders to be saved in Database.
2. Update Process flag to false
Expand Down
4 changes: 2 additions & 2 deletions WorkshopBackend/OrderService/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class OrderController : ControllerBase
private readonly IAmazonSQS _sqs;
private readonly IAmazonSimpleNotificationService _sns;
private readonly IAmazonEventBridge _eventBridge;
private readonly string _queueUrl = ""; // Format of https://.*
private readonly string _topicArn = ""; // Format of arn:aws.*
private readonly string _queueUrl = "https://sqs.eu-north-1.amazonaws.com/637423341661/jonashalvorsenOrderQueue"; // Format of https://.*
private readonly string _topicArn = "arn:aws:sns:eu-north-1:637423341661:jonashalvorsenOrderCreatedTopic"; // Format of arn:aws.*

public OrderController()
{
Expand Down
2 changes: 1 addition & 1 deletion WorkshopBackend/OrderService/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
}
},
"AllowedHosts": "*"
}
}