Container for the parameters to the GetItem operation. The GetItem operation returns a set of attributes for the item with the given primary key. If there is no matching item, GetItem does not return any data.

GetItem provides an eventually consistent read by default. If your application requires a strongly consistent read, set ConsistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value.

Inheritance: AmazonDynamoDBRequest
Example #1
0
        public int GetItem(string dbKey, string dbKeyValue, string table, out GetItemResponse paramResponse)
        {
            GetItemRequest request = new GetItemRequest();

            request.TableName = table;     // set the table name for DynamoDB
            request.Key = new Dictionary<string, AttributeValue>() { { dbKey, new AttributeValue { S = dbKeyValue } } };

            int response = (int)DBEnum.DBResponseCodes.DEFAULT_VALUE;

            try
            {
                paramResponse = this.client.GetItem(request);  // value set to NOT null

                //Check to see if entry exist
                if (0 == paramResponse.Item.Count) // Entry does not exist
                {
                    response = (int)DBEnum.DBResponseCodes.DOES_NOT_EXIST;
                }

                else // Entry exists
                {
                    response = (int)DBEnum.DBResponseCodes.SUCCESS;
                }

            }

            catch
            {
                response = (int)DBEnum.DBResponseCodes.DYNAMODB_EXCEPTION;  // set reponse to DB Exception flag
                paramResponse = null;       // set to null on Error
            }

            return response;
        }
Example #2
0
 // Get TestID
 public static void GetData1(int Id)
 {
     var Req = new Amazon.DynamoDBv2.Model.GetItemRequest
     {
         TableName = "TestID",
         Key = new Dictionary<string, Amazon.DynamoDBv2.Model.AttributeValue>() { {"Id",new Amazon.DynamoDBv2.Model.AttributeValue{N=Id.ToString()}}}
     };
     var Rsp = client.GetItem(Req);
     PrintItem(Rsp.GetItemResult.Item);
     Console.ReadLine();
 }
Example #3
0
        public static void GetData(string UID, string tableName)
        {
            Table testDB = Table.LoadTable(client, tableName);
            var request = new Amazon.DynamoDBv2.Model.GetItemRequest
            {
                TableName = tableName,
                Key = new Dictionary<string,Amazon.DynamoDBv2.Model.AttributeValue>()
                {{"UID",new Amazon.DynamoDBv2.Model.AttributeValue{S=UID}}}

            };

            var response = client.GetItem(request);
            var result = response.GetItemResult;
            Console.WriteLine("Units");
            Console.WriteLine(response.GetItemResult.ConsumedCapacity.CapacityUnits);
            Console.WriteLine("Data");
            Console.WriteLine(response.GetItemResult.Item.Count);
            Console.ReadLine();
        }
Example #4
0
        public bool CheckUserIsExist(string userID)
        {
            var config = new AmazonDynamoDBConfig();
            GetItemResponse response;
            config.ServiceURL = System.Configuration.ConfigurationManager.AppSettings["ServiceURL"];
            client = new AmazonDynamoDBClient(config);
            bool retval = false;
            try
            {
                GetItemRequest request = new GetItemRequest
                {
                    TableName = "User",
                    Key = new Dictionary<string, AttributeValue>() { { "UserID", new AttributeValue { S = userID } } },
                    ReturnConsumedCapacity = "TOTAL"
                };
                response = client.GetItem(request);
                retval = response.Item.Count > 0;
            }
            catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); }
            catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
            catch (Exception e) { Console.WriteLine(e.Message); }

            return retval;
        }
 /// <summary>
 /// Initiates the asynchronous execution of the GetItem operation.
 /// <seealso cref="Amazon.DynamoDBv2.AmazonDynamoDB.GetItem"/>
 /// </summary>
 /// 
 /// <param name="getItemRequest">Container for the necessary parameters to execute the GetItem operation on AmazonDynamoDBv2.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetItem
 ///         operation.</returns>
 public IAsyncResult BeginGetItem(GetItemRequest getItemRequest, AsyncCallback callback, object state)
 {
     return invokeGetItem(getItemRequest, callback, state, false);
 }
 /// <summary>
 /// The <i>GetItem</i> operation returns a set of attributes for the item with the given
 /// primary key. If there is no matching item, <i>GetItem</i> does not return any data.
 /// 
 ///  
 /// <para>
 /// <i>GetItem</i> provides an eventually consistent read by default. If your application
 /// requires a strongly consistent read, set <i>ConsistentRead</i> to <code>true</code>.
 /// Although a strongly consistent read might take more time than an eventually consistent
 /// read, it always returns the last updated value.
 /// </para>
 /// </summary>
 /// <param name="tableName">The name of the table containing the requested item.</param>
 /// <param name="key">A map of attribute names to <i>AttributeValue</i> objects, representing the primary key of the item to retrieve. For the primary key, you must provide all of the attributes. For example, with a hash type primary key, you only need to provide the hash attribute. For a hash-and-range type primary key, you must provide both the hash attribute and the range attribute.</param>
 /// <param name="consistentRead">A value that if set to <code>true</code>, then the operation uses strongly consistent reads; otherwise, eventually consistent reads are used.</param>
 /// 
 /// <returns>The response from the GetItem service method, as returned by DynamoDB.</returns>
 /// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
 /// An error occurred on the server side.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException">
 /// The request rate is too high, or the request is too large, for the available throughput
 /// to accommodate. The AWS SDKs automatically retry requests that receive this exception;
 /// therefore, your request will eventually succeed, unless the request is too large or
 /// your retry queue is too large to finish. Reduce the frequency of requests by using
 /// the strategies listed in <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html#APIRetries">Error
 /// Retries and Exponential Backoff</a> in the <i>Amazon DynamoDB Developer Guide</i>.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ResourceNotFoundException">
 /// The operation tried to access a nonexistent table or index. The resource might not
 /// be specified correctly, or its status might not be <code>ACTIVE</code>.
 /// </exception>
 public GetItemResponse GetItem(string tableName, Dictionary<string, AttributeValue> key, bool consistentRead)
 {
     var request = new GetItemRequest();
     request.TableName = tableName;
     request.Key = key;
     request.ConsistentRead = consistentRead;
     return GetItem(request);
 }
 IAsyncResult invokeGetItem(GetItemRequest getItemRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new GetItemRequestMarshaller().Marshall(getItemRequest);
     var unmarshaller = GetItemResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
        /// <summary>
        /// <para>The <i>GetItem</i> operation returns a set of attributes for the item with the given primary key. If there is no matching item,
        /// <i>GetItem</i> does not return any data.</para> <para> <i>GetItem</i> provides an eventually consistent read by default. If your application
        /// requires a strongly consistent read, set <i>ConsistentRead</i> to <c>true</c> . Although a strongly consistent read might take more time
        /// than an eventually consistent read, it always returns the last updated value.</para>
        /// </summary>
        /// 
        /// <param name="getItemRequest">Container for the necessary parameters to execute the GetItem service method on AmazonDynamoDBv2.</param>
        /// 
        /// <returns>The response from the GetItem service method, as returned by AmazonDynamoDBv2.</returns>
        /// 
        /// <exception cref="T:Amazon.DynamoDBv2.Model.ResourceNotFoundException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.InternalServerErrorException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<GetItemResponse> GetItemAsync(GetItemRequest getItemRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new GetItemRequestMarshaller();
            var unmarshaller = GetItemResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, GetItemRequest, GetItemResponse>(getItemRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
 /// <summary>
 /// The <i>GetItem</i> operation returns a set of attributes for the item with the given
 /// primary key. If there is no matching item, <i>GetItem</i> does not return any data.
 /// 
 ///  
 /// <para>
 /// <i>GetItem</i> provides an eventually consistent read by default. If your application
 /// requires a strongly consistent read, set <i>ConsistentRead</i> to <code>true</code>.
 /// Although a strongly consistent read might take more time than an eventually consistent
 /// read, it always returns the last updated value.
 /// </para>
 /// </summary>
 /// <param name="tableName">The name of the table containing the requested item.</param>
 /// <param name="key">A map of attribute names to <i>AttributeValue</i> objects, representing the primary key of the item to retrieve. For the primary key, you must provide all of the attributes. For example, with a hash type primary key, you only need to provide the hash attribute. For a hash-and-range type primary key, you must provide both the hash attribute and the range attribute.</param>
 /// 
 /// <returns>The response from the GetItem service method, as returned by DynamoDB.</returns>
 /// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
 /// An error occurred on the server side.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException">
 /// The request rate is too high, or the request is too large, for the available throughput
 /// to accommodate. The AWS SDKs automatically retry requests that receive this exception;
 /// therefore, your request will eventually succeed, unless the request is too large or
 /// your retry queue is too large to finish. Reduce the frequency of requests by using
 /// the strategies listed in <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html#APIRetries">Error
 /// Retries and Exponential Backoff</a> in the <i>Amazon DynamoDB Developer Guide</i>.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ResourceNotFoundException">
 /// The operation tried to access a nonexistent table or index. The resource might not
 /// be specified correctly, or its status might not be <code>ACTIVE</code>.
 /// </exception>
 public GetItemResponse GetItem(string tableName, Dictionary<string, AttributeValue> key)
 {
     var request = new GetItemRequest();
     request.TableName = tableName;
     request.Key = key;
     return GetItem(request);
 }
 /// <summary>
 /// The <i>GetItem</i> operation returns a set of attributes for the item with the given
 /// primary key. If there is no matching item, <i>GetItem</i> does not return any data.
 /// 
 ///  
 /// <para>
 /// <i>GetItem</i> provides an eventually consistent read by default. If your application
 /// requires a strongly consistent read, set <i>ConsistentRead</i> to <code>true</code>.
 /// Although a strongly consistent read might take more time than an eventually consistent
 /// read, it always returns the last updated value.
 /// </para>
 /// </summary>
 /// <param name="tableName">The name of the table containing the requested item.</param>
 /// <param name="key">A map of attribute names to <i>AttributeValue</i> objects, representing the primary key of the item to retrieve. For the primary key, you must provide all of the attributes. For example, with a hash type primary key, you only need to provide the hash attribute. For a hash-and-range type primary key, you must provide both the hash attribute and the range attribute.</param>
 /// <param name="consistentRead">Determines the read consistency model: If set to <code>true</code>, then the operation uses strongly consistent reads; otherwise, the operation uses eventually consistent reads.</param>
 /// <param name="cancellationToken">
 ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// 
 /// <returns>The response from the GetItem service method, as returned by DynamoDB.</returns>
 /// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
 /// An error occurred on the server side.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException">
 /// Your request rate is too high. The AWS SDKs for DynamoDB automatically retry requests
 /// that receive this exception. Your request is eventually successful, unless your retry
 /// queue is too large to finish. Reduce the frequency of requests and use exponential
 /// backoff. For more information, go to <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html#APIRetries">Error
 /// Retries and Exponential Backoff</a> in the <i>Amazon DynamoDB Developer Guide</i>.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ResourceNotFoundException">
 /// The operation tried to access a nonexistent table or index. The resource might not
 /// be specified correctly, or its status might not be <code>ACTIVE</code>.
 /// </exception>
 public Task<GetItemResponse> GetItemAsync(string tableName, Dictionary<string, AttributeValue> key, bool consistentRead, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
 {
     var request = new GetItemRequest();
     request.TableName = tableName;
     request.Key = key;
     request.ConsistentRead = consistentRead;
     return GetItemAsync(request, cancellationToken);
 }
		internal GetItemResponse GetItem(GetItemRequest request)
        {
            var task = GetItemAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
        /// <summary>
        /// Initiates the asynchronous execution of the GetItem operation.
        /// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the GetItem operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<GetItemResponse> GetItemAsync(GetItemRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new GetItemRequestMarshaller();
            var unmarshaller = GetItemResponseUnmarshaller.Instance;

            return InvokeAsync<GetItemRequest,GetItemResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
 /// <summary>
 /// The <i>GetItem</i> operation returns a set of attributes for the item with the given
 /// primary key. If there is no matching item, <i>GetItem</i> does not return any data.
 /// 
 ///  
 /// <para>
 /// <i>GetItem</i> provides an eventually consistent read by default. If your application
 /// requires a strongly consistent read, set <i>ConsistentRead</i> to <code>true</code>.
 /// Although a strongly consistent read might take more time than an eventually consistent
 /// read, it always returns the last updated value.
 /// </para>
 /// </summary>
 /// <param name="tableName">The name of the table containing the requested item.</param>
 /// <param name="key">A map of attribute names to <i>AttributeValue</i> objects, representing the primary key of the item to retrieve. For the primary key, you must provide all of the attributes. For example, with a hash type primary key, you only need to provide the hash attribute. For a hash-and-range type primary key, you must provide both the hash attribute and the range attribute.</param>
 /// <param name="consistentRead">A value that if set to <code>true</code>, then the operation uses strongly consistent reads; otherwise, eventually consistent reads are used.</param>
 /// 
 /// <returns>The response from the GetItem service method, as returned by DynamoDB.</returns>
 /// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
 /// An error occurred on the server side.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException">
 /// The request rate is too high, or the request is too large, for the available throughput
 /// to accommodate. The AWS SDKs automatically retry requests that receive this exception;
 /// therefore, your request will eventually succeed, unless the request is too large or
 /// your retry queue is too large to finish. Reduce the frequency of requests by using
 /// the strategies listed in <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html#APIRetries">Error
 /// Retries and Exponential Backoff</a> in the <i>Amazon DynamoDB Developer Guide</i>.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ResourceNotFoundException">
 /// The operation tried to access a nonexistent table or index. The resource might not
 /// be specified correctly, or its status might not be <code>ACTIVE</code>.
 /// </exception>
 public void GetItemAsync(string tableName, Dictionary<string, AttributeValue> key, bool consistentRead, AmazonServiceCallback<GetItemRequest, GetItemResponse> callback, AsyncOptions options = null)
 {
     var request = new GetItemRequest();
     request.TableName = tableName;
     request.Key = key;
     request.ConsistentRead = consistentRead;
     GetItemAsync(request, callback, options);
 }
Example #14
0
        public Dictionary<string, object> GetUser(string userID)
        {
            Dictionary<string, object> retval = new Dictionary<string, object>();
            GetItemResponse response;
            var config = new AmazonDynamoDBConfig();
            config.ServiceURL = System.Configuration.ConfigurationManager.AppSettings["ServiceURL"];
            client = new AmazonDynamoDBClient(config);
            try
            {
                GetItemRequest request = new GetItemRequest
                {
                    TableName = "User",
                    Key = new Dictionary<string, AttributeValue>() { { "UserID", new AttributeValue { S = userID } } },
                    ReturnConsumedCapacity = "TOTAL"
                };
                response = client.GetItem(request);
                retval.Add("UserID", response.Item["UserID"].S);
                retval.Add("HeadshotURL", response.Item["HeadshotURL"].S);
                retval.Add("IsPayUser", Convert.ToBoolean(response.Item["IsPayUser"].S));
                retval.Add("UserName", response.Item["UserName"].S);
                retval.Add("RegistDate", response.Item["RegistDate"].N);
                retval.Add("LastLoginDate", response.Item["LastLoginDate"].N);
                retval.Add("LastSyncDate", response.Item["LastSyncDate"].N);
            }
            catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); }
            catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
            catch (Exception e) { Console.WriteLine(e.Message); }

            return retval;
        }
 /// <summary>
 /// <para>The <i>GetItem</i> operation returns a set of attributes for the item with the given primary key. If there is no matching item,
 /// <i>GetItem</i> does not return any data.</para> <para> <i>GetItem</i> provides an eventually consistent read by default. If your application
 /// requires a strongly consistent read, set <i>ConsistentRead</i> to <c>true</c> . Although a strongly consistent read might take more time
 /// than an eventually consistent read, it always returns the last updated value.</para>
 /// </summary>
 /// 
 /// <param name="getItemRequest">Container for the necessary parameters to execute the GetItem service method on AmazonDynamoDBv2.</param>
 /// 
 /// <returns>The response from the GetItem service method, as returned by AmazonDynamoDBv2.</returns>
 /// 
 /// <exception cref="ResourceNotFoundException"/>
 /// <exception cref="ProvisionedThroughputExceededException"/>
 /// <exception cref="InternalServerErrorException"/>
 public GetItemResponse GetItem(GetItemRequest getItemRequest)
 {
     IAsyncResult asyncResult = invokeGetItem(getItemRequest, null, null, true);
     return EndGetItem(asyncResult);
 }
Example #16
0
        internal Document GetItemHelper(Key key, GetItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new GetItemOperationConfig();
            var request = new GetItemRequest
            {
                TableName = TableName,
                Key = key,
                ConsistentRead = currentConfig.ConsistentRead
            };
            request.BeforeRequestEvent += isAsync ?
                new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                new RequestEventHandler(UserAgentRequestEventHandlerSync);
            if (currentConfig.AttributesToGet != null)
                request.WithAttributesToGet(currentConfig.AttributesToGet);

            var result = DDBClient.GetItem(request);
            var attributeMap = result.GetItemResult.Item;
            if (attributeMap == null)
                return null;
            return Document.FromAttributeMap(attributeMap);
        }
        public void Get_item_with_AWSSDK()
        {
            db.PutItem(new Todo { Id = 1, Content = "TODO 1", Order = 1 });

            var request = new GetItemRequest
            {
                TableName = "Todo",
                Key = new Dictionary<string, AttributeValue> {
                    { "Id", new AttributeValue { N = "1"} }
                },
                ConsistentRead = true,
            };

            var response = awsDb.GetItem(request);
            var todo = new Todo
            {
                Id = Convert.ToInt64(response.Item["Id"].N),
                Content = response.Item["Content"].S,
                Order = Convert.ToInt32(response.Item["Order"].N),
                Done = response.Item["Done"].BOOL,
            };

            todo.PrintDump();
        }
        /// <summary>
        /// Initiates the asynchronous execution of the GetItem operation.
        /// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB.GetItem"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the GetItem operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<GetItemResponse> GetItemAsync(GetItemRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new GetItemRequestMarshaller();
            var unmarshaller = GetItemResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, GetItemRequest, GetItemResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
Example #19
0
        public void CRUDSamples()
        {
            EnsureTables();

            PutSample();

            {
                #region GetItem Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item key
                //  Hash-key of the target item is string value "Mark Twain"
                //  Range-key of the target item is string value "The Adventures of Tom Sawyer"
                Dictionary<string, AttributeValue> key = new Dictionary<string, AttributeValue>
                {
                    { "Author", new AttributeValue { S = "Mark Twain" } },
                    { "Title", new AttributeValue { S = "The Adventures of Tom Sawyer" } }
                };

                // Create GetItem request
                GetItemRequest request = new GetItemRequest
                {
                    TableName = "SampleTable",
                    Key = key,
                };

                // Issue request
                var result = client.GetItem(request);

                // View response
                Console.WriteLine("Item:");
                Dictionary<string, AttributeValue> item = result.Item;
                foreach (var keyValuePair in item)
                {
                    Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                        keyValuePair.Key,
                        keyValuePair.Value.S,
                        keyValuePair.Value.N,
                        string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                        string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                }

                #endregion
            }

            {
                #region UpdateItem Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item key
                //  Hash-key of the target item is string value "Mark Twain"
                //  Range-key of the target item is string value "The Adventures of Tom Sawyer"
                Dictionary<string, AttributeValue> key = new Dictionary<string, AttributeValue>
                {
                    { "Author", new AttributeValue { S = "Mark Twain" } },
                    { "Title", new AttributeValue { S = "The Adventures of Tom Sawyer" } }
                };

                // Define attribute updates
                Dictionary<string, AttributeValueUpdate> updates = new Dictionary<string, AttributeValueUpdate>();
                // Update item's Setting attribute
                updates["Setting"] = new AttributeValueUpdate()
                {
                    Action = AttributeAction.PUT,
                    Value = new AttributeValue { S = "St. Petersburg, Missouri" }
                };
                // Remove item's Bibliography attribute
                updates["Bibliography"] = new AttributeValueUpdate()
                {
                    Action = AttributeAction.DELETE
                };   
                // Add a new string to the item's Genres SS attribute
                updates["Genres"] = new AttributeValueUpdate()
                {
                    Action = AttributeAction.ADD,
                    Value = new AttributeValue { SS = new List<string> { "Bildungsroman" } }
                };

                // Create UpdateItem request
                UpdateItemRequest request = new UpdateItemRequest
                {
                    TableName = "SampleTable",
                    Key = key,
                    AttributeUpdates = updates
                };

                // Issue request
                client.UpdateItem(request);

                #endregion
            }

            {
                #region DeleteItem Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item key
                //  Hash-key of the target item is string value "Mark Twain"
                //  Range-key of the target item is string value "The Adventures of Tom Sawyer"
                Dictionary<string, AttributeValue> key = new Dictionary<string, AttributeValue>
                {
                    { "Author", new AttributeValue { S = "Mark Twain" } },
                    { "Title", new AttributeValue { S = "The Adventures of Tom Sawyer" } }
                };

                // Create DeleteItem request
                DeleteItemRequest request = new DeleteItemRequest
                {
                    TableName = "SampleTable",
                    Key = key
                };

                // Issue request
                client.DeleteItem(request);

                #endregion
            }
        }
 /// <summary>
 /// Initiates the asynchronous execution of the GetItem operation.
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the GetItem operation on AmazonDynamoDBClient.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void GetItemAsync(GetItemRequest request, AmazonServiceCallback<GetItemRequest, GetItemResponse> callback, AsyncOptions options = null)
 {
     options = options == null?new AsyncOptions():options;
     var marshaller = new GetItemRequestMarshaller();
     var unmarshaller = GetItemResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<GetItemRequest,GetItemResponse> responseObject 
                     = new AmazonServiceResult<GetItemRequest,GetItemResponse>((GetItemRequest)req, (GetItemResponse)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<GetItemRequest>(request, marshaller, unmarshaller, options, callbackHelper);
 }
        internal GetItemResponse GetItem(GetItemRequest request)
        {
            var marshaller = new GetItemRequestMarshaller();
            var unmarshaller = GetItemResponseUnmarshaller.Instance;

            return Invoke<GetItemRequest,GetItemResponse>(request, marshaller, unmarshaller);
        }
		internal GetItemResponse GetItem(GetItemRequest request)
        {
            var task = GetItemAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
Example #23
0
        internal Document GetItemHelper(Key key, GetItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new GetItemOperationConfig();
            var request = new GetItemRequest
            {
                TableName = TableName,
                Key = key,
                ConsistentRead = currentConfig.ConsistentRead
            };

            ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)request).AddBeforeRequestHandler(isAsync ?
                new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                new RequestEventHandler(UserAgentRequestEventHandlerSync)
                );
            if (currentConfig.AttributesToGet != null)
                request.AttributesToGet = currentConfig.AttributesToGet;

            var result = DDBClient.GetItem(request);
            var attributeMap = result.Item;
            if (attributeMap == null || attributeMap.Count == 0)
                return null;
            return Document.FromAttributeMap(attributeMap);
        }
        /// <summary>
        /// Initiates the asynchronous execution of the GetItem operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the GetItem operation on AmazonDynamoDBClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetItem
        ///         operation.</returns>
        public IAsyncResult BeginGetItem(GetItemRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new GetItemRequestMarshaller();
            var unmarshaller = GetItemResponseUnmarshaller.Instance;

            return BeginInvoke<GetItemRequest>(request, marshaller, unmarshaller,
                callback, state);
        }