AuthUsingTempSessionTokenDotNet
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. To get temporary security credentials and access Amazon S3, do the following:
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
GetSessionToken
method of the STS client you created in the preceding step. You provide session information to this method using aGetSessionTokenRequest
object.The method returns your temporary security credentials.
Package the temporary security credentials in an instance of the
SessionAWSCredentials
object. You use this object to provide the temporary security credentials to your Amazon S3 client.Create an instance of the
AmazonS3Client
class 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.