Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent configuration section names in SDK and its documentation #624

Closed
betabandido opened this issue Apr 21, 2017 · 7 comments
Closed
Assignees
Labels
guidance Question that needs advice or information.

Comments

@betabandido
Copy link

While trying to use an app.config file to store my AWS profile and some DynamoDB-related information, I have found out some inconsistencies between the section names actually supported by the SDK and the ones described in the documentation.

According to http://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-ref.html#net-dg-config-ref the way to specify the profile name is by using the profileName tag as in:

<aws
  profileName="development"
  <!-- ... -->
</aws>

However, in ConfigurationExtensions.cs a tag named profile is looked for (instead of profileName).

I am loading the app.config file as follows:

Configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddXmlFile("app.config")
    .Build();

The following statement:

Configuration.GetAWSOptions().Profile

returns null if profileName is used, but it returns the correct profile name if profile is used instead.

A similar, but probably unrelated problem, occurs when trying to specify the table name prefix in the app.config file. According to the documentation (same link as above), the way to specify the prefix is as follows:

<aws
  <!-- ... -->
  <dynamoDB>
    <dynamoDBContext
      tableNamePrefix="string value">
   </dynamoDBContext>
  </dynamoDB>
</aws>

But, in AWSConfigs.DynamoDB.cs the key to access this property is defined as:

public const string DynamoDBContextTableNamePrefixKey = "AWS.DynamoDBContext.TableNamePrefix";

It seems the dynamoDB tag is missing (compared to the documentation). Moreover, I believe that the table name prefix is intended to be read from the configuration in the following statement:

this.TableNamePrefix = AWSConfigs.GetConfig(AWSConfigsDynamoDB.DynamoDBContextTableNamePrefixKey);

See code here.

But, if I am not mistaken, that method is implemented here and it just returns null:

public static string GetConfig(string name)
{
    return null;
}

So, it seems the tableNamePrefix tag might not be supported for .NET core.

I have managed to have it working by adding the following statements to my application:

AWSConfigsDynamoDB.Context.TableNamePrefix = Configuration
    .GetSection("aws")?
    .GetSection("dynamoDB")?
    .GetSection("dynamoDBContext")?["tableNamePrefix"];

Where Configuration is the result of using the ConfigurationBuilder (as shown earlier).

But, I wonder whether there is a better way to do it.

Environment

  • AWSSDK.Core version used: 3.3.12
  • Operating System and version: Windows 10
  • Visual Studio version: 2017
  • Targeted .NET platform: .NET core 1.0

.NET Core Info

  • .NET Core version used for development: .NET core 1.0
  • .NET Core version installed in the environment where application runs: .NET core 1.0
  • Output of dotnet --info:
.NET Command Line Tools (1.0.3)

Product Information:
 Version:            1.0.3
 Commit SHA-1 hash:  37224c9917

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.3
  • Contents of project.json/project.csproj:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AWSSDK.Core" Version="3.3.12" />
    <PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.4.6" />
    <PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.0.3" />
    <PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.0" />
  </ItemGroup>

  <ItemGroup>
    <None Update="app.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>
@betabandido betabandido changed the title Inconsistent section names in SDK and its documentation Inconsistent configuration section names in SDK and its documentation Apr 21, 2017
@sstevenkang
Copy link
Contributor

Hi, it looks like you are looking at the wrong documentation. Notice that there's a separate configuration documentation page for .Net Core which specifies Profile as the key instead of profileName.

Regarding the DynamoDB problem you encountered, are you creating the service client as suggested in the documentation?

var options = Configuration.GetAWSOptions();
IAmazonS3 client = options.CreateServiceClient<IAmazonS3>();

@sstevenkang sstevenkang self-assigned this May 4, 2017
@betabandido
Copy link
Author

What about the documentation for other fields such as tableNamePrefix? Do they follow the format described in the page I referenced?

Yes, I create the client following the approach you mentioned.

I created a minimal example showing the problem where DynamoDBContextConfig is not initialized with the expected table name prefix. In the appsettings.json file I placed the tableNamePrefix setting both directly under the AWS node and under the DynamoDB node (as it is not very clear from the documentation where it should be placed).

@sstevenkang
Copy link
Contributor

No they do not. System.Configuration namespace is not supported in CoreCLR and this breaks how service specific configuration is consumed by each client. The AWSSDK.Extensions.NETCore.Setup is our package that supports a few critical configurations like credentials & region.

We'll update the docs to make this clear.

@betabandido
Copy link
Author

Is there any recommended way to set up the table name prefix from the configuration file in .NET core?

@PavelSafronov
Copy link

There is no mechanism yet for the .NET Core version of the SDK to get the value from the file, but once you do get this value from a configuration into your application, you can apply it globally by setting AWSConfigsDynamoDB.Context.TableNamePrefix.

@diehlaws diehlaws added guidance Question that needs advice or information. and removed Question labels Jan 3, 2019
@rtellez91
Copy link

There is no mechanism yet for the .NET Core version of the SDK to get the value from the file, but once you do get this value from a configuration into your application, you can apply it globally by setting AWSConfigsDynamoDB.Context.TableNamePrefix.

Is there any better way to do this? I read that way would be deprecated.

@unleashed-jamest
Copy link

unleashed-jamest commented Sep 28, 2020

There is still no way to set the table name prefix through the .NET Core configuration system in 2020?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

6 participants