Getting Started

Simple AmazonSQS Transport usage

NuGet Package: NServiceBus.AmazonSQS (6.x)
Target Version: NServiceBus 8.x

This sample shows the basic usage of SQS as a transport for NServiceBus. The application sends messages between two endpoints, via the SQS transport, and writes a message to the console when a message is received.

AWS setup

Security and access configuration

Add the AWS Access Key ID and AWS Secret Access Key to the following environment variables:

  • Access Key ID in AWS_ACCESS_KEY_ID
  • Secret Access Key in AWS_SECRET_ACCESS_KEY
  • Default Region in AWS_REGION

See also AWS Account Identifiers, Managing Access Keys for an AWS Account, and IAM Security Credentials.

See also AWS Regions for a list of available regions.


Several Amazon SQS queues are required to run this sample. These will be created at start-up via the installer mechanism of NServiceBus. The queues can be seen in the SQS management UI.

  • Samples-Sqs-Simple: The main message processing queue.
  • Samples-Sqs-Simple-Retries: Queue used for delayed retries.
  • error: Queue used for error handling.


An Amazon S3 bucket is required to leverage the S3 bucket for large messages feature of the SQS transport. Create an S3 bucket and replace the bucketname in the sample startup with the name of the created bucket.

Endpoint configuration

Configure the endpoints to use the SQS transport.

var endpointConfiguration = new EndpointConfiguration("Samples.Sqs.SimpleSender");

var transport = new SqsTransport
    S3 = new S3Settings("bucketname", "my/key/prefix")

var routing = endpointConfiguration.UseTransport(transport);

Run the sample

Start the endpoints. Two console applications will be started, a receiver endpoint can send commands or publish events to the subscriber endpoint. In addition, large message bodies can be sent using S3 as the storage for the message payload.

View a message in transit

To view a message in transit, stop the receiver endpoint while sending/publishing further messages from the sender endpoint. The messages will be written to SQS but not dequeued. The message can now be viewed in the SQS management UI.

The large message contents can be viewed in the S3 management UI.

See also Receiving and Deleting a Message from an Amazon SQS Queue.

Related Articles