Path: blob/master/doc_source/AuthUsingTempSessionTokenDotNet.md
4080 views
Making requests using IAM user temporary credentials - AWS SDK for .NET
An IAM user or an AWS account can request temporary security credentials using the AWS SDK for .NET and use them to access Amazon S3. These credentials expire after the session duration.
By default, the session duration is one hour. If you use IAM user credentials, you can specify the duration when requesting the temporary security credentials from 15 minutes to the maximum session duration for the role. For more information about temporary security credentials, see Temporary Security Credentials in the IAM User Guide. For more information about making requests, see Making requests.
To get temporary security credentials and access Amazon S3
Create an instance of the AWS Security Token Service client,
AmazonSecurityTokenServiceClient. For information about providing credentials, see Using the AWS SDKs, CLI, and Explorers.Start a session by calling the
GetSessionTokenmethod of the STS client you created in the preceding step. You provide session information to this method using aGetSessionTokenRequestobject.The method returns your temporary security credentials.
Package the temporary security credentials in an instance of the
SessionAWSCredentialsobject. You use this object to provide the temporary security credentials to your Amazon S3 client.Create an instance of the
AmazonS3Clientclass by passing in the temporary security credentials. You send requests to Amazon S3 using this client. If you send requests using expired credentials, Amazon S3 returns an error.
Note If you obtain temporary security credentials using your AWS account security credentials, those credentials are valid for only one hour. You can specify a session duration only if you use IAM user credentials to request a session.
The following C# example lists object keys in the specified bucket. For illustration, the example obtains temporary security credentials for a default one-hour session and uses them to send authenticated request to Amazon S3.
If you want to test the sample using IAM user credentials, you need to create an IAM user under your AWS account. For more information about how to create an IAM user, see Creating Your First IAM User and Administrators Group in the IAM User Guide. For more information about making requests, see Making requests.
For instructions on creating and testing a working example, see Running the Amazon S3 .NET Code Examples.