AWS SDK for .NET Developer Guide Version v2.0.
AWS SDK for .NET Developer Guide AWS SDK for .NET: Developer Guide Copyright © 2014 Amazon Web Services, Inc. and/or its affiliates. All rights reserved. All trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon. AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
AWS SDK for .NET Developer Guide Table of Contents AWS SDK for .NET Developer Guide ................................................................................................ 1 How to Use This Guide ........................................................................................................... 1 Supported Services and Revision History .................................................................................. 2 About Amazon Web Services .............................................
AWS SDK for .NET Developer Guide Conclusion ................................................................................................................. Creating and Using an Amazon SQS Queue ............................................................................ Create an Amazon SQS Client ....................................................................................... Create an Amazon SQS Queue .....................................................................................
AWS SDK for .NET Developer Guide How to Use This Guide AWS SDK for .NET Developer Guide The AWS SDK for .NET is a single downloadable package that includes Visual Studio project templates, the AWS .NET library, C# code samples, and documentation. The AWS SDK for .NET makes it easier for Windows developers to build .
AWS SDK for .NET Developer Guide Supported Services and Revision History Programming with the AWS SDK for .NET (p. 8) The basics of how to implement applications with the SDK for .NET that applies to all AWS services. This chapter also includes information about how to migrate code to the latest version of the SDK for .NET, and describes the differences between the last version and this one. Tutorials and Examples (p. 31) A set of tutorials, walkthroughs and examples of how to use the SDK for .
AWS SDK for .NET Developer Guide AWS Account and Credentials Getting Started with the AWS SDK for .NET To get started with the AWS SDK for .NET, set up the following: • AWS Account and Credentials • .NET Development Environment • SDK for .NET AWS Account and Credentials To access AWS, you need an AWS account. To sign up for an AWS account 1. 2. Go to http://amazonaws.cn, and then click Sign Up. Follow the on-screen instructions.
AWS SDK for .NET Developer Guide .NET Development Environment inserted at build time. This approach ensures that your credentials are not unintentionally exposed with your project on a public site. For more information, see Setting Up the AWS Toolkit for Visual Studio and Configuring AWS Credentials (p. 9). For more information on IAM, including how to create IAM users and groups, and how to use roles to provide temporary credentials to applications running on EC2 instances, see What Is IAM?.
AWS SDK for .NET Developer Guide Starting a New Project To install the SDK for .NET 1. Go to http://amazonaws.cn/sdkfornet. 2. Click the Download button in the upper right corner of the page. Your browser will prompt you to save the install file. To begin the install process, open the saved install file and follow the on-screen instructions. You can optionally install extensions for the SDK for .NET, which include a session state provider and a trace listener.
AWS SDK for .NET Developer Guide Starting a New Project To create a new AWS Management Console project 1. In Visual Studio, on the File menu, select New, and then click Project to open the New Project dialog box. 2. Select AWS from the list of installed templates, and then select the AWS project template you want to use. Enter a project name, and then click OK. 3. Use the AWS Access Credentials dialog box to configure your application.
AWS SDK for .NET Developer Guide Starting a New Project The Toolkit for Visual Studio adds two key-value pairs to appSettings, based on the values you specified in the AWS Access Credentials dialog box: • AWSProfileName – specifies the profile name. • AWSRegion – specifies the default region. 5. Click F5 to compile and run the application, which prints the number of Amazon EC2 instances, Amazon SimpleDB tables, and Amazon S3 buckets in your account.
AWS SDK for .NET Developer Guide Configuring Your Application Programming with the AWS SDK for .NET This section provides general programming techniques and information for developing software with the AWS SDK for .NET. Topics • Configuring Your AWS SDK for .NET Application (p. 8) • AWS Region Selection (p. 16) • Amazon Web Services Asynchronous APIs for .NET (p. 16) • Migrating Your Code to the Latest Version of the AWS SDK for .NET (p. 24) • Platform Differences in the AWS SDK for .NET (p.
AWS SDK for .NET Developer Guide Configuring AWS Credentials You can also configure an SDK for .NET application programmatically, by setting property values in the AWSConfigs class. The following example specifies the AWSRegion (p. 14) and AWSLogging (p. 13) parameters: AWSConfigs.AWSRegion = "us-west-2"; AWSConfigs.Logging = LoggingOptions.Log4Net; Programmatically defined parameters override any values that were specified in an App.config or Web.config file.
AWS SDK for .NET Developer Guide Configuring AWS Credentials Topics • Using the SDK Store (p. 10) • Using a Credentials File (p. 10) • Using Credentials in an Application (p. 11) Using the SDK Store The preferred way to manage credentials for SDK for .NET applications is to add a profile to the SDK Store for each set of credentials that you want to use in your applications. • The SDK Store can contain multiple profiles from any number of accounts.
AWS SDK for .NET Developer Guide Configuring AWS Credentials [profile_name] aws_access_key_id = accessKey aws_secret_access_key = secretKey A profile can optionally include a session token. For more information, see Best Practices for Managing AWS Access Keys. Tip If you include a profile named default, the SDK for .NET will use that profile by default if it cannot find the specified profile. By default, the SDK for .NET searches for profiles only in the user's home directory.
AWS SDK for .NET Developer Guide Configuring AWS Credentials This example assumes that you are using the SDK Store or a credentials file in the default location, under the current user's home directory. If your profiles are stored in a credentials file in an arbitrary location, specify the location by adding an AWSProfilesLocation value to appSettings.
AWS SDK for .NET Developer Guide Additional Application Parameters AmazonS3Config config = new AmazonS3Config(); config.ProxyCredentials = new NetworkCredential("foo", "bar"); Earlier versions of the SDK used ProxyUsername and ProxyPassword, but these properties have been deprecated. Configuring Other Application Parameters In addition to configuring credentials (p. 9), you can configure a number of other application parameters: • AWSEndpointDefinition (p. 13) • AWSLogging (p.
AWS SDK for .NET Developer Guide Additional Application Parameters You can set multiple values at once, separated by commas. To set both log4net and System.Diagnostics logging in the .config file, use: Using the SDK for .NET API, combine the values of the LoggingOptions enumeration and set the AWSConfigs.Logging property: AWSConfigs.Logging = LoggingOptions.Log4Net | LoggingOptions.
AWS SDK for .NET Developer Guide Additional Application Parameters To set service logging with the SDK for .NET API, set the AWSConfigs.ResponseLogging property to one of the values of the ResponseLoggingOption enumeration: AWSConfigs.ResponseLogging = ResponseLoggingOption.OnError; Changes to this setting take effect immediately. AWS.DynamoDBContext.TableNamePrefix Configures the default TableNamePrefix that the DynamoDBContext will use if not manually configured. To set the table name prefix in the .
AWS SDK for .NET Developer Guide AWS Region Selection By default, this setting is false, though Signature Version 4 may be used by default in some cases or with some regions. When the setting is true, Signature Version 4 will be used for all requests. Changes to this setting take effect only for new Amazon EC2 client instances. AWS Region Selection AWS regions allow you to access AWS services that reside physically in a specific geographic region.
AWS SDK for .NET Developer Guide Asynchronous API for .NET 4.5, Windows Store, and Windows Phone 8 Asynchronous API for .NET 4.5, Windows Store, and Windows Phone 8 The AWS SDK for .NET uses the new task-based asynchronous pattern for .NET 4.5, Windows Store, and Windows Phone 8.You can use the async and await keywords to perform and manage asynchronous operations for all AWS products without blocking.
AWS SDK for .NET Developer Guide Asynchronous API for .NET 3.5 void Callback(IAsyncResult asyncResult) Object state The third parameter, state, is a user-defined object that is made available to the callback function as the AsyncState property of the asyncResult parameter, that is, asyncResult.AsyncState. Calling Patterns • Passing a callback function and a state object. • Passing a callback function, but passing null for the state object.
AWS SDK for .NET Developer Guide Asynchronous API for .NET 3.5 No Callback Specified The following example code calls BeginPutObject, performs some work, then calls EndPutObject to retrieve the service response.The call to EndPutObject is enclosed in a try block to catch any exceptions that might have been thrown during the operation. asyncResult = client.BeginPutObject(request, null, null); while ( ! asyncResult.IsCompleted ) { // // Do some work here // } try { response = client.
AWS SDK for .NET Developer Guide Asynchronous API for .NET 3.5 } } The following line of code calls BeginPutObject and specifies the preceding callback function. When the PutObject operation completes, the callback function is called. In this example, the call to BeginPutObject specifies the Amazon S3 client object for the state parameter. The callback function uses the client to call the EndPutObject method to retrieve the server response.
AWS SDK for .NET Developer Guide Asynchronous API for .NET 3.5 called. The callback function uses the Amazon S3 client object to call the EndPutObject method to retrieve the server response. The callback also extracts the start time for the operation and uses it to print the time it took for the asynchronous operation to complete. As in the previous examples, because exceptions that occur during the operation are received when EndPutObject is called, this call is placed within a try block.
AWS SDK for .NET Developer Guide Asynchronous API for .NET 3.5 { Console.WriteLine("Finished PutObject operation with simple callback"); Console.Write("\n\n"); } public static void CallbackWithClient(IAsyncResult asyncResult) { try { AmazonS3Client s3Client = (AmazonS3Client) asyncResult.AsyncState; PutObjectResponse response = s3Client.EndPutObject(asyncResult); Console.WriteLine("Finished PutObject operation with client call back"); Console.WriteLine("Service Response:"); Console.
AWS SDK for .NET Developer Guide Asynchronous API for .NET 3.5 // Create a PutObject request // // You will need to change the BucketName below in order to run this // sample code. // PutObjectRequest request = new PutObjectRequest { BucketName = "PUT-YOUR-OWN-EXISTING-BUCKET-NAME-HERE", Key = "Item", ContentBody = "This is sample content..." }; response = client.PutObject(request); Console.WriteLine("Finished PutObject operation for {0}.", request.Key); Console.WriteLine("Service Response:"); Console.
AWS SDK for .NET Developer Guide Migrating Your Code to the Latest SDK See Also • Getting Started (p. 3) • Programming with the AWS SDK for .NET (p. 8) Migrating Your Code to the Latest Version of the AWS SDK for .NET This guide describes changes in the latest version of the SDK, and how you can migrate your code to the latest SDK. Topics • Introduction (p. 24) • What's New (p. 24) • What's Different (p. 24) Introduction The AWS SDK for .NET was released in November 2009 and was originally designed for .
AWS SDK for .NET Developer Guide What's Different • The version 2 runtime for .NET 3.5 is similar to the existing version 1 runtime, which is based on the System.Net.HttpWebRequest class and uses the Begin and End pattern for asynchronous methods. • The version 2 runtime for .NET 4.5 is based on the new System.Net.Http.HttpClient class and uses Tasks for asynchronous methods, which enables users to use the new async and await keywords in C# 5.0.
AWS SDK for .NET Developer Guide What's Different • All client interfaces have been renamed to follow the .NET convention of starting with the letter "I". For example, the AmazonEC2 class is now IAmazonEC2. • Properties for collections have been properly pluralized. • AWSClientFactory.CreateAmazonSNSClient has been renamed CreateAmazonSimpleNotificationServiceClient. • AWSClientFactory.CreateAmazonIdentityManagementClient has been renamed CreateAmazonIdentityManagementServiceClient.
AWS SDK for .NET Developer Guide What's Different • The GenerateMD5 property has been removed from PutObjectRequest and UploadPartRequest because this is now automatically computed as the object is being written to Amazon S3 and compared against the MD5 returned in the response from Amazon S3. • The PutBucketTagging.TagSets collection is now PutBucketTagging.TagSet, and now takes a list of Tag objects.
AWS SDK for .NET Developer Guide Platform Differences Refer to the return value type of the Create* method for the service client that you're using to see what values are returned. These are all listed in the AWS SDK for .NET API Reference. Platform Differences in the AWS SDK for .NET The AWS SDK for .NET provides four distinct assemblies for developers to target different platforms. However, not all SDK functionality is available on each of these platforms.
AWS SDK for .NET Developer Guide Install AWS Assemblies with NuGet This version of the SDK for .NET supports only the following services. This is the same set of services as those supported in the AWS SDK for Android and the AWS SDK for iOS.
AWS SDK for .NET Developer Guide NuGet Package Manager Console From the Manage NuGet Packages dialog box, select Online in the left pane. You can then search for the package that you want to install using the search box in the upper right corner. The screenshot shows the AWS.Extensions assembly package. Notice that NuGet is aware that this package has a dependency on the AWSSDK assembly package; NuGet will therefore install the AWSSDK package if it is not already installed.
AWS SDK for .NET Developer Guide IAM Roles for Amazon EC2 Instances AWS SDK for .NET Tutorials and Examples This chapter provides tutorials, walkthroughs, and examples of programming Amazon Web Services with the AWS SDK for .NET. Since these topics generally provide buildable and runnable examples of SDK for .NET programming, it is expected that you have already set up the AWS SDK for .NET (p. 3) and that you understand the material in the Programming with the AWS SDK for .NET (p. 8) chapter.
AWS SDK for .NET Developer Guide Use IAM Roles for Amazon EC2 Instances to Manage Your Credentials numbers of instances. It also doesn't work well for instances that are created by AWS on behalf of the customer, such as Spot Instances or instances in Auto Scaling groups. Another strategy is to embed the credentials as literal strings in the software itself. However, this means that anyone who comes into possession of the software can scan through the code and retrieve the credentials.
AWS SDK for .NET Developer Guide Walkthrough: Using IAM Roles to Retrieve an Amazon S3 Object from an Amazon EC2 Instance Walkthrough: Using IAM Roles to Retrieve an Amazon S3 Object from an Amazon EC2 Instance In this walkthrough, we consider a program that retrieves an object from Amazon S3 using regular credentials. We then modify the program so that it uses IAM roles for Amazon EC2 Instances.
AWS SDK for .NET Developer Guide Walkthrough: Using IAM Roles to Retrieve an Amazon S3 Object from an Amazon EC2 Instance } FileStream s = new FileStream( "s3Object.txt", FileMode.Create ); StreamWriter writer = new StreamWriter( s ); writer.WriteLine( responseBody ); } catch (AmazonS3Exception s3Exception) { Console.WriteLine(s3Exception.Message, s3Exception.InnerException); } } // main } // class } // namespace You can test this program, by filling in your own credentials in an App.config.
AWS SDK for .NET Developer Guide Walkthrough: Using IAM Roles to Retrieve an Amazon S3 Object from an Amazon EC2 Instance 3. Edit the Source File to Remove the Credentials 4. Transfer the Compiled Program to Your Amazon EC2 Instance 5. Run the Program Create the Role The first step is to create an IAM role that has the appropriate permissions. To create the IAM role, follow the procedure Creating an IAM Role in Using IAM.
AWS SDK for .NET Developer Guide Walkthrough: Using IAM Roles to Retrieve an Amazon S3 Object from an Amazon EC2 Instance your Amazon EC2 instance. When you create the Amazon EC2 instance, specify the IAM role that you created previously in the IAM console. When you create your Amazon EC2 instance, you will also need to specify a key pair and a security group. Specify a key pair for which you have the private key (PEM file) stored on your local computer.
AWS SDK for .NET Developer Guide Walkthrough: Using IAM Roles to Retrieve an Amazon S3 Object from an Amazon EC2 Instance using (GetObjectResponse response = client.GetObject(request)) { using (Stream responseStream = response.ResponseStream) { using (StreamReader reader = new StreamReader(responseStream)) { responseBody = reader.ReadToEnd(); } } } } FileStream s = new FileStream( "s3Object.txt", FileMode.Create ); StreamWriter writer = new StreamWriter( s ); writer.
AWS SDK for .NET Developer Guide Walkthrough: Using IAM Roles to Retrieve an Amazon S3 Object from an Amazon EC2 Instance You should configure your Remote Desktop session so that you can access your local drives from the Amazon EC2 instance. If you use the shortcut provided by the AWS Management Console, right-click the shortcut and select Edit. On the Local Resources tab, in the Local devices and resources section, click the More button.
AWS SDK for .NET Developer Guide Managing ASP.NET Session State with Amazon DynamoDB Run the Program Run the program. Ensure that the AWS assembly is either in the same directory as the program or that you have installed it in the General Assembly Cache. get-object.exe The program downloads the object and writes its contents to a file called s3Object.txt. Managing ASP.NET Session State with Amazon DynamoDB ASP.NET applications often store session-state data in memory.
AWS SDK for .NET Developer Guide Create the ASP.NET_SessionState Table Create the ASP.NET_SessionState Table When your application starts, it looks for an Amazon DynamoDB table named, by default, ASP.NET_SessionState. We recommend that you create this table before you run your application for the first time. To create the ASP.NET_SessionState table 1. Sign in to the AWS Management Console and open the Amazon DynamoDB console at https://console.amazonaws.cn/dynamodb/. 2. Click Create Table.
AWS SDK for .NET Developer Guide Configure the Session State Provider Configure the Session State Provider To configure an ASP.NET application to use DynamoDB as the session state server 1. Add references to both AWSSDK.dll and AWS.SessionProvider.dll to your Visual Studio ASP.NET project. These assemblies are available by installing the AWS SDK for .NET (p. 4) or you can install them using NuGet (p. 29).
AWS SDK for .NET Developer Guide Security Considerations Region Required string attribute.The AWS region in which to use Amazon DynamoDB. For a list of available AWS regions, go to the Regions and Endpoints documentation. Application Optional string attribute. The value of the Application attribute is used to partition the session data in the table so that the same table can be used for more than one application. Table Optional string attribute. The name of the table used to store session data.
AWS SDK for .NET Developer Guide Tutorial: Creating Amazon EC2 Instances Tutorial: Creating Amazon EC2 Instances with the AWS SDK for .NET This topic demonstrates how to use the AWS SDK for .NET to create, start, and terminate Amazon Elastic Compute Cloud (Amazon EC2) instances. The sample code in this topic is written in C#, but you can use the AWS SDK for .NET with any language that is compatible with the Microsoft .NET Framework. The AWS SDK for .
AWS SDK for .NET Developer Guide Specify an Amazon EC2 Security Group var ec2Client = new AmazonEC2Client(RegionEndpoint.USEast1); The client object's permissions are determined by the policy that is attached to the profile that you specified in App.config. To specify the service endpoint, pass the appropriate RegionEndpoint value to the constructor. For a list of Amazon EC2 service endpoints, see Regions and Endpoints.
AWS SDK for .NET Developer Guide Specify an Amazon EC2 Security Group To enumerate existing security groups 1. Obtain a list of your account's security groups. DescribeSecurityGroupsRequest secGroupRequest = new DescribeSecurityGroupsRequest(); DescribeSecurityGroupsResponse secGroupResponse = ec2Client.DescribeSecurityGroups(secGroupRequest); List secGroups = secGroupResponse.SecurityGroups; 2.
AWS SDK for .NET Developer Guide Authorize Security Group Ingress CreateSecurityGroupResponse newGroupResponse = ec2Client.CreateSecurityGroup(newGroupRequest); Pass the request object to the Amazon EC2 client's CreateSecurityGroup method, which returns a CreateSecurityGroupResponse object. 3. Optionally, you can obtain the SecurityGroup object for the group that you just created by using the To select an existing security group (p. 44) procedure described earlier.
AWS SDK for .NET Developer Guide Specify an Amazon EC2 Key Pair • Set the GroupName property to the security group name of. • Add the IpPermissionSpecification object from Step 1 to the group's IpPermissions collection. 3. Authorize ingress. AuthorizeSecurityGroupIngressResponse ingressResponse = ec2Client.AuthorizeSecurityGroupIngress(ingressRequest); Pass the request object to Amazon EC2 client's AuthorizeSecurityGroupIngress method, which returns an AuthorizeSecurityGroupIngressResponse object.
AWS SDK for .NET Developer Guide Launch Amazon EC2 Instances DescribeKeyPairsRequest keyPairDescriptionRequest = new DescribeKeyPairsRequest(); DescribeKeyPairsResponse keyPairDescriptionResponse = ec2Client.DescribeKeyPairs(keyPairDescriptionRequest); List keyPairs = keyPairDescriptionResponse.KeyPairs; foreach (KeyPairInfo item in keyPairs) { if (item.
AWS SDK for .NET Developer Guide Launch Amazon EC2 Instances var runInstancesRequest = new RunInstancesRequest() { ImageId = "ami-62c44d52", InstanceType = "m1.small", MinCount = 1, MaxCount = 1, KeyName = keyName }; runInstancesRequest.SecurityGroups.Add(secGroupName); To configure the request object: • Specify which Amazon Machine Image (AMI) your instances will use by setting the ImageId property to an appropriate public or privately-provided image ID.
AWS SDK for .NET Developer Guide Launch Amazon EC2 Instances RunInstancesResponse runResponse = ec2Client.RunInstances(runInstances Request); 3. You can use the returned RunInstancesResponse object to get a list of instance IDs for the new instances. List instances = runResponse.Reservation.Instances; List instanceIDs = new List(); foreach (Instance item in instances) { instanceIDs.Add(item.
AWS SDK for .NET Developer Guide Terminate Amazon EC2 Instances The DescribeInstancesResponse object's DescribeInstancesResult.Reservations property contains a list of reservations. In this case, there is only one. Each reservation contains a list of Instance objects, each of which represents one of the reservation's EC2 instances. You can get the instance's status from an Instance object's InstanceState.
AWS SDK for .NET Developer Guide Tutorial: Amazon EC2 Spot Instances Resource Description Windows & .NET Developer Center Sample code, documentation, tools, and additional resources to help you build applications on Amazon Web Services. Amazon EC2 Documentation Amazon EC2 service documentation.
AWS SDK for .NET Developer Guide Prerequisites Prerequisites This tutorial assumes that you have signed up for AWS, set up your .NET development environment, and installed the AWS SDK for .NET. If you use the Microsoft Visual Studio development environment, we recommend that you also install the AWS Toolkit for Visual Studio. For instructions on setting up your environment, see Getting Started (p. 3). Step 1: Setting Up Your Credentials To begin using this code sample, you need to populate the App.
AWS SDK for .NET Developer Guide Step 2: Setting Up a Security Group 10 } catch (AmazonEC2Exception ae) { if (string.Equals(ae.ErrorCode, "InvalidGroup.Duplicate", StringCompar ison.InvariantCulture)) { 15 Console.WriteLine(ae.Message); } else { throw; 20 } } To enable access to the group, we create an ipPermission object with the IP address set to the CIDR representation of the IP address of the local computer.
AWS SDK for .NET Developer Guide Step 3: Submitting Your Spot Request throw; 15 } } You can also create the security group using the AWS Toolkit for Visual Studio. Go to the toolkit documentation for more information. Step 3: Submitting Your Spot Request To submit a Spot Request, you first need to determine the instance type, the Amazon Machine Image (AMI), and the maximum bid price you want to use.
AWS SDK for .NET Developer Guide Step 3: Submitting Your Spot Request There are many ways to approach bidding for Spot instances. To get a broad overview of the various approaches, you should view the Bidding for Spot Instances video. However, to get started, we'll describe three common strategies: bid to ensure cost is less than on-demand pricing; bid based on the value of the resulting computation; bid so as to acquire computing capacity as quickly as possible.
AWS SDK for .NET Developer Guide Step 4: Determining the State of Your Spot Request be fulfilled. You can determine the types of available instances and the On-Demand prices for instances by going to Amazon EC2 Pricing page. To request a Spot Instance, you simply need to build your request with the parameters we have specified so far. We start by creating a RequestSpotInstanceRequest object. The request object requires the number of instances you want to start (2) and the bid price ($0.03).
AWS SDK for .NET Developer Guide Step 4: Determining the State of Your Spot Request SpotInstancesResult.SpotInstanceRequest) { describeRequest.SpotInstanceRequestId.Add(spotInstanceRequest.SpotIn stanceRequestId); 10 } 1 // Create a variable that will track whether there are any // requests still in the open state. bool anyOpen; 5 // Create a list to store any instances that were activated.
AWS SDK for .NET Developer Guide Step 5: Cleaning up Your Spot Requests and Instances Console.WriteLine(e.Message); } 50 if (anyOpen) { // Wait for the requests to go active. Console.WriteLine("Requests still in open state, will retry in 60 seconds."); 55 Thread.Sleep((int)TimeSpan.FromMinutes(1).TotalMilliseconds); } } while (anyOpen); If you just ran the code up to this point, your Spot Instance Request would complete—or possibly fail with an error.
AWS SDK for .NET Developer Guide Conclusion To terminate any outstanding instances, we use the instanceIds array, which we populated with the instance IDs of those instances that transitioned to the active state. We terminate these instances by assigning this array to the InstanceId member of a TerminateInstancesRequest object, then passing that object to the ec2.TerminateInstances API. 1 if (instanceIds.
AWS SDK for .NET Developer Guide Create an Amazon SQS Client Create an Amazon SQS Client You will need an Amazon SQS client in order to create and use an Amazon SQS queue. Before configuring your client, you should create an App.Config file to specify your AWS credentials. You specify your credentials by referencing the appropriate profile in the appSettings section of the file. The following example specifys a profile named my_profile.
AWS SDK for .NET Developer Guide Amazon SQS Queue URLs To create an Amazon SQS queue 1. Create and initialize a CreateQueueRequest instance. Provide the name of your queue and specify a visibility timeout for your queue messages, as follows: CreateQueueRequest createQueueRequest = new CreateQueueRequest(); createQueueRequest.QueueName = "MySQSQueue"; createQueueRequest.DefaultVisibilityTimeout = 10; Your queue name must only be composed of alphanumeric characters, hyphens, and underscores.
AWS SDK for .NET Developer Guide Receive a Message from an Amazon SQS Queue Important Due to the distributed nature of the queue, Amazon SQS cannot guarantee you will receive messages in the exact order they are sent. If you require that message order be preserved, place sequencing information in each message so you can reorder the messages upon receipt. To send a message to an Amazon SQS queue 1. Create and initialize a SendMessageRequest instance.
AWS SDK for .NET Developer Guide Delete a Message from an Amazon SQS Queue ReceiveMessageResponse receiveMessageResponse = amazonSQSClient.ReceiveMessage(receiveMessageRequest); The method returns a ReceiveMessageResponse instance, containing the list of messages the queue contains. 3. The response object contains a ReceiveMessageResult member. This member includes a Messages list.
AWS SDK for .NET Developer Guide Related Resources DeleteMessageResponse response = amazonSQSClient.DeleteMessage(deleteMessageRequest); Calling DeleteMessage unconditionally removes the message from the queue, regardless of the visibility timeout setting. For more information about visibility timeouts, go to Visibility Timeout. For information about sending a message to a queue, see Send an Amazon SQS Message (p. 62).
AWS SDK for .NET Developer Guide Additional Resources Home Page for AWS SDK for .NET For more information about the AWS SDK for .NET, go to the home page for the SDK at http://amazonaws.cn/sdkfornet. SDK Reference Documentation The SDK reference documentation includes the ability to browse and search across all code included with the SDK. It provides thorough documentation, usage examples, and even the ability to browse method source. For more information, see the AWS SDK for .NET API Reference.
AWS SDK for .NET Developer Guide Document History The following table describes the important changes since the last release of the AWS SDK for .NET Developer Guide. Last documentation update: November 8, 2013 Change Description Release Date Support for .NET SDK version 2 This guide has been modified to support the latest version November 8, 2013 of the AWS SDK for .NET. New topic This topic tracks recent changes to the AWS SDK for .NET September 9, 2013 Developer Guide.