简体   繁体   中英

Unable to connect to AWS SDK AmazonEC2Client through C#

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM