Error when trying to start up endpoint using AmazonSQS

I’m getting the following error when trying to use AmazonSQS.

An unhandled exception of type ‘System.Collections.Generic.KeyNotFoundException’ occurred in mscorlib.dll

Additional information: The given key (NServiceBus.AmazonSQS.Region) was not present in the dictionary.

I have the env variable AWS_REGION=‘us-east-1’ set, but it is acting like it cannot find it.

Hi Ray,

Could you please provide configuration code for the endpoint?

Thank you,


Hi Ray,

Thank you for the config, but is it copied as is? For example,

Looks wrong as you’d need to have something like


to get the transport working.

In addition to your original configuraion code, could you also provide packages and versions you’re including in the project? Do not omit any packages, as that might be a key to what you’re seen. I.e. there might be more than a single transport referenced.

Thank you,

I must have copied the wrong thing. I actually do have SqsTransport in there.


Here are the NuGet packages installed:

AWSSDK.Core v3.3.21.9
AWSSDK.S3 v3.3.16.2
AWSSDK.SQS v3.3.3.2
DnsClient v1.0.7
log4net v2.0.8
Microsoft.Diagnostics.Tracing.EventSource.Redist v1.1.28
MongoDB.Bson v2.5.0
MongoDB.Driver v2.5.0
MongoDB.Driver.Core v2.5.0
Newtonsoft.Json v10.0.3
NServiceBus v6.4.3
NServiceBus.AmazonSQS v3.1.0
NServiceBus.Host v7.0.2
System.Buffers v4.4.0
System.Runtime.InteropServices.RuntimeInformation v4.3.0

Ok, so I found this and added it:

transport.Region(region: Environment.GetEnvironmentVariable(“AWS_REGION”, EnvironmentVariableTarget.User));

Now I get a different error:

2018-02-01 10:03:45.450 FATAL NServiceBus.Hosting.Windows.WindowsHost Start failure
System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN were not set with AWS credentials.
at Amazon.Runtime.EnvironmentVariablesAWSCredentials.FetchCredentials()
at NServiceBus.AmazonSQS.AwsClientFactory.CreateCredentials(ConnectionConfiguration connectionConfiguration) in C:\BuildAgent\work\63bcc2eb1764a99b\src\NServiceBus.AmazonSQS\AwsClientFactory.cs:line 16
at NServiceBus.AmazonSQS.AwsClientFactory.CreateSqsClient(ConnectionConfiguration connectionConfiguration) in C:\BuildAgent\work\63bcc2eb1764a99b\src\NServiceBus.AmazonSQS\AwsClientFactory.cs:line 44
at NServiceBus.TransportInfrastructure…ctor(SettingsHolder settings) in C:\BuildAgent\work\63bcc2eb1764a99b\src\NServiceBus.AmazonSQS\Configure\TransportInfrastructure.cs:line 21
at NServiceBus.SqsTransport.Initialize(SettingsHolder settings, String connectionString) in C:\BuildAgent\work\63bcc2eb1764a99b\src\NServiceBus.AmazonSQS\Configure\SqsTransport.cs:line 36
at NServiceBus.InitializableEndpoint.d__1.MoveNext() in C:\BuildAgent\work\a93f853f0c1b9532\src\NServiceBus.Core\InitializableEndpoint.cs:line 49

I have the key and secret key set in env variables. I do not have a token set.

Hi Ray,

Is this SQS sample you’re running or a custom endpoint?
In case this is a custom endpoint, could you please share your code?


Hi Ray

How are you starting the host? As a Windows Service or a console application? In which level are the env variables set?

For example if you start it as a console application this should be enough

public class EndpointConfig : IConfigureThisEndpoint
    public void Customize(EndpointConfiguration endpointConfiguration)



        var transport = endpointConfiguration.UseTransport<SqsTransport>();
        transport.Region(Environment.GetEnvironmentVariable("AWS_REGION", EnvironmentVariableTarget.User));


When you start it as a Window Service that variables need to be either on the system level, assigned to the user that runs the windows service, explicitly set in code via

        Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "VALUE", EnvironmentVariableTarget.Process);
        Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", "VALUE", EnvironmentVariableTarget.Process);

or you can use any of the other ways to retrieve the keys described in

Hope that helps