aws-sdk-net: Can't set USEast1RegionalEndpointValue property of AmazonS3Config due to an exception in the constructor.
AmazonS3Config inherits ClientConfig which calls the virtual Initialize method. AmazonS3Config overrides Initialize and calls UpdateEndpointForUsEast1Regional. So users of the AmazonS3Config class don’t have a chance to set the USEast1RegionalEndpointValue property before UpdateEndpointForUsEast1Regional is called.
Expected Behavior
This is what I want to do, but currently new AmazonS3Config() throws an exception.
var awsCredentials = new BasicAWSCredentials("MyAccessKey", "MySecretKey");
var amazonS3Config = new AmazonS3Config();
amazonS3Config.RegionEndpoint = RegionEndpoint.USEast1;
amazonS3Config.USEast1RegionalEndpointValue = S3UsEast1RegionalEndpointValue.Regional;
var amazonS3Client = new AmazonS3Client(awsCredentials, amazonS3Config);
Current Behavior
My company has our own secret management system so we don’t use the AWS SDK credential manager. We also run our websites as a network service if that makes a difference. When creating an instance of AmazonS3Config we get the following error.
System.TypeInitializationException: The type initializer for 'Amazon.Runtime.Internal.Settings.PersistenceManager' threw an exception. ---> System.UnauthorizedAccessException: Access to the path 'C:\Windows\system32\config\systemprofile' is denied.
at System.IO.FileSystem.CreateDirectory(String fullPath)
at System.IO.Directory.CreateDirectory(String path)
at Amazon.Runtime.Internal.Settings.PersistenceManager..cctor()
--- End of inner exception stack trace ---
at Amazon.Util.Internal.SettingsManager.GetSettings()
at Amazon.Util.Internal.SettingsManager.TryGetObjectByProperty(String propertyName, String value, String& uniqueKey, Dictionary`2& properties)
at Amazon.Runtime.CredentialManagement.NetSDKCredentialsFile.TryGetProfile(String profileName, CredentialProfile& profile)
at Amazon.Runtime.CredentialManagement.CredentialProfileStoreChain.TryGetProfile(String profileName, CredentialProfile& profile)
at Amazon.S3.AmazonS3Config.CheckCredentialsFile()
at Amazon.S3.AmazonS3Config.GetEndpointFlagValueForUsEast1Regional()
at Amazon.S3.AmazonS3Config.UpdateEndpointForUsEast1Regional()
at Amazon.S3.AmazonS3Config.Initialize()
at Amazon.Runtime.ClientConfig..ctor()
at Amazon.S3.AmazonS3Config..ctor()
Possible Solution
Remove the call to UpdateEndpointForUsEast1Regional from Initialize. Maybe call it from the constructor of AmazonS3Client instead. Adding a try/catch block could also solve the issue.
Steps to Reproduce (for bugs)
Restrict access to the path that credential files are stored in. Then run the code snippet from the Expected Behavior section. When run on our Windows servers under the Network Service user the sdk tries to go to this path: “C:\Windows\system32\config\systemprofile”.
Context
I want to set the USEast1RegionalEndpointValue property in code so the sdk doesn’t try to fetch it from a file or environment variable, because we don’t have that set up.
Your Environment
- AWSSDK.Core version used: 3.3.104.7
- AWSSDK.S3 version used: 3.3.110.2
- .NET Core version used: 2.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 16 (5 by maintainers)
Commits related to this issue
- Downgrade AWSSDK to 3.3.109.4 due to https://github.com/aws/aws-sdk-net/issues/1490 — committed to genexuslabs/DotNetClasses by cmurialdo 7 years ago
- Downgrade AWSSDK to 3.3.109.4 due to https://github.com/aws/aws-sdk-net/issues/1490 (#117) Co-authored-by: claudia <cmurialdo@gmail.com> — committed to genexuslabs/DotNetClasses by claudiamurialdo 7 years ago
Thank you. I installed the latest version and things are working as expected.