我的要求是将我的 AWS 相关配置保存在其自己的文件中(如 Web.AWS.Config),我的应用程序是一个 .NET 4.6 Web 应用程序,并且我已使其按以下方式工作。我遵循了下面的文档。非常感谢任何帮助!提前致谢。
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Amazon/TAWSConfigs.html
<configSections>
<section name="aws" type="Amazon.AWSSection, AWSSDK.Core"/>
</configSections>
<aws configSource="Web.AWS.config"></aws>
在我的 Web.AWS.config 文件中,我有以下内容
<aws profileName="dev" profilesLocation="C:\temp\awscredentials\credentials-file">
<IdentityPoolId>eu-west-1:62484b27-39ce-4db8-8bcb</IdentityPoolId>
</aws>
AWS 开发工具包能够正确读取“profileName”和“profilesLocation”,但无法读取“IdentityPoolId”的自定义值。下面的代码可以从我的单独 Web.AWS.Config 文件中读取与 aws 相关的配置,而不会出现任何问题。
CredentialProfile basicProfile;
AWSCredentials awsCredentials;
var sharedFile = new SharedCredentialsFile();
if (sharedFile.TryGetProfile("dev", out basicProfile) && AWSCredentialsFactory.TryGetAWSCredentials(basicProfile, sharedFile, out awsCredentials))
{
if (awsCredentials != null)
{
try
{
AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient(awsCredentials, RegionEndpoint.EUWest1);
//more code here ----
}
catch(Exception xxx)
{
//handle error
}
}
}
事实上,这个标签完全是为了适应一种包含我的池 ID 的方式。当我将鼠标放在下面的“服务部分”下时,我可以看到自定义值。但是看不到一个简单的方法来阅读它。
非常感谢任何帮助。如果可能的话,我想在没有太多复杂的解决方法的情况下读取“ServiceSections”中的值。
