Skip to content

JHalvor/csharp-cloud-aws-day-4

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# Cloud AWS - Day Four

Commands to Set Up SQS, SNS, and EventBridge

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)

jonashalvorsen - example ajdewilzin - this can be your name, independent of your login details

eu-north-1 - example eu-north-1

Steps

  1. Create an SNS Topic:
aws sns create-topic --name jonashalvorsenOrderCreatedTopic

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.

  1. Create an SQS Queue:
aws sqs create-queue --queue-name jonashalvorsenOrderQueue

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: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.

  1. Create an EventBridge Event Bus:
aws events create-event-bus --name jonashalvorsenCustomEventBus --region eu-north-1
  1. Create an EventBridge Rule:
aws events put-rule --name jonashalvorsenOrderProcessedRule --event-pattern '{\"source\": [\"order.service\"]}' --event-bus-name jonashalvorsenCustomEventBus

Without \

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).

  1. Subscribe the SQS Queue to the SNS Topic
aws sqs get-queue-attributes --queue-url https://sqs.eu-north-1.amazonaws.com/637423341661/jonashalvorsenOrderQueue --attribute-name QueueArn --region eu-north-1
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
  1. Grant SNS Permissions to SQS

In Bash/Unix terminals you can run this command:

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
  3. Process orders and update the Total amount from QTY * AMOUNT
  4. Update Process flag to true

Extension Exercise

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%