.NET Core IoT and IotData in the same app - how do I configure this?


I'm trying to write a simple .NET core web app that makes some calls to interact with AWS IoT. I wanted to be able to search or list things and get their current shadow. I believe I need to use the IoT service to search and list, and IotData to get thing shadows. I'm running into a problem however where I can't seem to find a configuration that works for both.

If I don't have ServiceURL specified in the Appconfig.Development.json, IotData throws

AmazonClientException: No RegionEndpoint or ServiceURL configured

If I provide ServiceURL with the endpoint listed in our AWS IoT dashboard "ENDPOINT.iot.REGION.amazonaws.com", IotData calls begin to work but the IoT service calls fail with the exception

ResourceNotFoundException: Not Found

If I remove all of the IotData code and add the "Region" field to Appconfig.Development.json with our region, the IoT calls begin to work.

If I uncomment the IotData calls with the "Region" field, I get

AmazonClientException: The RegionEndpoint property is not applicable for AmazonIotDataClient and should not be set.

In the past I've used Boto3 in Python and didn't have to configure any of this this way; the region was specified in ~/.aws/config and never had to provide a Service URL, and I've written scripts that used both services, so I'm very confused as to what the issue is.

I'm also certain I have the correct permissions with the keys I'm using as I'm able to perform all of these operations from the AWS CLI. Does anyone have any recommendations on how to configure this so that both services work?

For reference, this is a simple example of what I'm trying to do: https://gist.github.com/nathan-miller-actigraph/6cd18c99ee2ee4ca05fb5f74598287ae (the actual application is a .NET Core 2.1 SPA).

asked 4 years ago89 views
1 Answer

I figured it out. For anyone who runs into this same problem, you can create a second section in your appsettings.json:

    "AwsIotDataConfig": {
        "Profile": "default",
        "ServiceURL": "https://data.iot.us-east-1.amazonaws.com/"
    "AwsConfig": {
        "Profile": "default",
        "Region": "us-east-1"

then in your Startup.cs, when you call GetAWSOptions, you can pass in the name of the config section:

            var awsGenericOptions = Configuration.GetAWSOptions("AwsConfig");

            var awsIotDataOptions = Configuration.GetAWSOptions("AwsIotDataConfig");

and when you add the IotData service, specify that it should use the IotData specific options:

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions