Note in Every command and URL being called there are fields that need to be replaced.
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
{region}
- example eu-north-1
- Create an SNS Topic:
aws sns create-topic --name {studentName}OrderCreatedTopic
If successful, you will see in your terminal a JSON response that includes "TopicArn": "...
.
Replace topicArn
in your Controller code with the generated TopicArn
value from above.
- Create an SQS Queue:
aws sqs create-queue --queue-name {studentName}OrderQueue
If successful, you will see in your terminal a JSON response that includes "QueueUrl": "some_aws_url
.
Replace queueUrl
in your Controller code with the generated QueueUrl
from the above command.
aws sns subscribe --topic-arn arn:aws:sns:{region}:637423341661:{studentName}OrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:{region}:637423341661:{studentName}OrderQueue
You don't need to save the generated SubscriptionArn.
- Create an EventBridge Event Bus:
aws events create-event-bus --name {StudentName}CustomEventBus --region {region}
- Create an EventBridge Rule:
aws events put-rule --name {StudentName}OrderProcessedRule --event-pattern '{\"source\": [\"order.service\"]}' --event-bus-name {StudentName}CustomEventBus
If your terminal complains about double quotes, you might need to remove the backslash \
from the command above (and commands later on).
- Subscribe the SQS Queue to the SNS Topic
aws sqs get-queue-attributes --queue-url https://sqs.{region}.amazonaws.com/637423341661/{studentName}OrderQueue --attribute-name QueueArn --region {region}
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}
- Grant SNS Permissions to SQS
In Bash/Unix terminals you can run this command:
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}
Get the existing code working.
It works to an extent but there are limits and bugs, for instance it doensn't interact with the database.
- Make the application store data into the database (this could be an RDS one or a Neon one)
- Process orders and update the Total amount from QTY * AMOUNT plus
- Add code to make it possible to update the existing orders in the database and remove the processed ones from the message queue
- Improve the code in other ways