Home > Net >  Unable to connect to AWS SDK AmazonEC2Client through C#
Unable to connect to AWS SDK AmazonEC2Client through C#

Time:02-10

I am trying to connect to AWS via the SDK and the examples I am finding say connect via the following method:

string accessKey = "****************GCDE";    
string SecretAccessKey = "****************oeE7";    
AmazonEC2Client(accessKey,SecretAccessKey,RegionEndpoint.USWest2);

DescribeInstancesRequest request = new DescribeInstancesRequest();

But this throws the following exception...

HResult=0x80131500 Message=AWS was not able to validate the provided access credentials Source=AWSSDK.Core

CodePudding user response:

After a few hours of head scratching and looking at different samples online I finally figured it out. Since I am using Microsoft Single Sign ON (SSO), to authenticate a token is required.

string accessKey = "****************GCDE";    
string SecretAccessKey = "****************oeE7";    
string sessionToken = "****************oeE7";    

var tempCredentials = new SessionAWSCredentials(
            accessKey,
            SecretAccessKey,
            sessionToken);

 var _client = new AmazonEC2Client(tempCredentials,RegionEndpoint.USWest2);
 DescribeInstancesRequest request = new DescribeInstancesRequest();
  •  Tags:  
  • Related