User guide
Table Of Contents
- AWS SDK for .NET
- Table of Contents
- AWS SDK for .NET Developer Guide
- Getting Started with the AWS SDK for .NET
- Programming with the AWS SDK for .NET
- AWS SDK for .NET Tutorials and Examples
- Managing ASP.NET Session State with Amazon DynamoDB
- Tutorial: Creating Amazon EC2 Instances with the AWS SDK for .NET
- Tutorial: Grant Access Using an IAM Role and the AWS SDK for .NET
- Tutorial: Amazon EC2 Spot Instances
- Creating and Using an Amazon SQS Queue with the AWS SDK for .NET
- Creating an Amazon Route 53 Hosted Zone and Adding Resource Record Sets
- Additional Resources
- Document History

responseBody = reader.ReadToEnd();
}
}
using (FileStream s = new FileStream( "s3Object.txt", FileMode.Create
))
using (StreamWriter writer = new StreamWriter(s)) {
writer.WriteLine( responseBody );
}
}
catch (AmazonS3Exception s3Exception) {
Console.WriteLine(s3Exception.Message, s3Exception.InnerException);
}
} // main
} // class
} // namespace
To test the sample code
1. Open Visual Studio and create an AWS Console project.
2. Replace the code in the Program.cs file with the sample code.
3. Replace bucket-name with the name of your Amazon S3 bucket and folder/file-name.txt
with the name of a text file in the bucket.
4. Compile and run the sample program. If the program succeeds, it displays the following output and
creates a file named s3Object.txt on your local drive that contains the text it retrieved from the
text file in Amazon S3.
Retrieving (GET) an object
If the program fails, ensure that you are using credentials that provide you with access to the bucket.
5. (Optional) Transfer the sample program to a running Windows instance on which you haven't set up
credentials. Run the program and verify that it fails because it can't locate credentials.
Create an IAM Role
Create an IAM role that has the appropriate permissions to access Amazon S3.
To create the IAM role
1. Open the IAM console.
2. In the navigation pane, click Roles, and then click Create New Role.
3. Enter a name for the role, and then click Next Step. Remember this name, as you'll need it when
you launch your EC2 instance.
4. Under AWS Service Roles, select Amazon EC2. Under Select Policy Template, select Amazon
S3 Read Only Access. Review the policy and then click Next Step.
5. Review the role information and then click Create Role.
Launch an EC2 Instance and Specify the IAM Role
You can launch an EC2 instance with an IAM role using the Amazon EC2 console or the SDK for .NET.
Version v2.0.0
49
AWS SDK for .NET Developer Guide
Create an IAM Role