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
Binary file added Images/aws_sqs_queue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/swagger_get.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/swagger_post.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 15 additions & 10 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
`tvaltn` - 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 tvaltnOrderCreatedTopic
```
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 tvaltnOrderQueue
```

If successful, you will see in your terminal a JSON response that includes `"QueueUrl": "some_aws_url`.
Expand All @@ -31,21 +31,21 @@ 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:tvaltnOrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:eu-north-1:637423341661:tvaltnOrderQueue
```

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 tvaltnCustomEventBus --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 tvaltnOrderProcessedRule --event-pattern '{\"source\": [\"order.service\"]}' --event-bus-name tvaltnCustomEventBus
```

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,19 +54,24 @@ 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/tvaltnOrderQueue --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:tvaltnOrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:eu-north-1:637423341661:tvaltnOrderQueue --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/tvaltnOrderQueue --attributes '{"Policy":"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"SQS:SendMessage\",\"Resource\":\"arn:aws:sqs:eu-north-1:637423341661:tvaltnOrderQueue\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:sns:eu-north-1:637423341661:tvaltnOrderCreatedTopic\"}}}]}"}' --region eu-north-1
```

With a json file instead (Run this from the root directory of this repo):
```bash
aws sqs set-queue-attributes --queue-url https://sqs.eu-north-1.amazonaws.com/637423341661/tvaltnOrderQueue --attributes file://attributes.json --region eu-north-1
```


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/tvaltnOrderQueue"; // Format of https://.*
private readonly string _topicArn = "arn:aws:sns:eu-north-1:637423341661:tvaltnOrderCreatedTopic"; // 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
@@ -1,7 +1,7 @@
{
"AWS": {
"Profile": "default",
"Region": "us-west-2"
"Region": "eu-north-1"
},
"Logging": {
"LogLevel": {
Expand Down
1 change: 1 addition & 0 deletions WorkshopBackend/WorkshopBackend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrderService", "OrderServic
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E49EF9F2-F493-4887-B8CF-FCF54A7C151D}"
ProjectSection(SolutionItems) = preProject
attributes.json = attributes.json
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down
1 change: 1 addition & 0 deletions attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"SQS:SendMessage\",\"Resource\":\"arn:aws:sqs:eu-north-1:637423341661:tvaltnOrderQueue\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:sns:eu-north-1:637423341661:tvaltnOrderCreatedTopic\"}}}]}" }