在我们公司中,我们必须通过SAML获得临时的AWS凭证。我编写了一个小应用程序,该应用程序登录到我们的内部表单中,获取了SAML声明,完成了所有AssumeRole
的工作,并最终获得了凭据。我在.aws/config
中这样设置:
[default]
region=eu-west-1
output=json
credential_process=C:\OurCreds\ObtainOurCreds.exe eu-west-1 3600 123456789012:role/MyRole
我可以在命令行工具中使用它:
PS C:\Somewhere> aws s3 ls
2019-04-23 16:09:45 foo-bar-baz-12345
2019-04-30 08:06:29 quux-bletch-moo-54321
但是我不知道如何在代码中做到这一点。
像这样使用过时的StoredProfileAWSCredentials
:
var credentials = new StoredProfileAWSCredentials("default");
会引发异常:
System.ArgumentException: 'App.config does not contain credentials information. Either add the AWSAccessKey and AWSSecretKey properties or the AWSProfileName property.'
像这样使用SharedCredentialsFile
:
var scf = new SharedCredentialsFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aws", "config"));
if(scf.TryGetProfile(profileName, out var profile) &&
AWSCredentialsFactory.TryGetAWSCredentials(profile, scf, out var creds)) {
// never getting here
}
导致设置了profile
,但未填充creds
。
是否可以通过编程方式使用credential_process
,如果可以,我应该怎么做?