LocalStack is a tool to develop and test your AWS applications locally, reducing development time and increasing productivity.
Refer to the official LocalStack documentation to learn how to install and run it locally.
To configure an NServiceBus endpoint to connect to LocalStack instead of AWS, the AWS endpoint URL must be set to the address of the LocalStack instance. The simplest way is by defining the AWS_ENDPOINT_URL
environment variable and setting its value to the LocalStack URL:
AWS_ENDPOINT_URL=http://localhost.localstack.cloud:4566
Alternatively, configure the AWS SDK ServiceURL
configuration property, like in the following example programmatically for the Amazon SQS transport:
var amazonSqsConfig = new AmazonSQSConfig();
amazonSqsConfig.ServiceURL = "http://localhost.localstack.cloud:4566";
var amazonSqsClient = new AmazonSQSClient(amazonSqsConfig);
Similarly, the Amazon SNS and DynamoDB configurations must follow the same patter. The following snippet shows the SNS configuration:
var amazonSnsConfig = new AmazonSimpleNotificationServiceConfig();
amazonSnsConfig.ServiceURL = "http://localhost.localstack.cloud:4566";
var amazonSnsClient = new AmazonSimpleNotificationServiceClient(amazonSnsConfig);
The DynamoDB configuration is shown in the following example:
var amazonDynamoDBConfig = new AmazonDynamoDBConfig();
amazonDynamoDBConfig.ServiceURL = "http://localhost.localstack.cloud:4566";
var amazonDynamoDBClient = new AmazonDynamoDBClient(amazonDynamoDBConfig);
Remember that, even if you are not connecting to AWS cloud services, it is still required to specify access credentials and region. From the LocalStack perspective they could be fake values, like the following:
AWS_ACCESS_KEY_ID=demo
AWS_SECRET_ACCESS_KEY=demo
AWS_REGION=us-east-1