public async Task <APIGatewayProxyResponse> DeleteAlbum(APIGatewayProxyRequest req, ILambdaContext context) { var logger = context.Logger; logger.LogLine($"request {JsonConvert.SerializeObject(req)}"); logger.LogLine($"context {JsonConvert.SerializeObject(context)}"); var archiveTable = Environment.GetEnvironmentVariable("ARCHIVE_TABLE"); logger.LogLine($"archiveTable {archiveTable}"); var photosBucket = Environment.GetEnvironmentVariable("PHOTOS_BUCKET"); var thumbnailsBucket = Environment.GetEnvironmentVariable("THUMBNAILS_BUCKET"); var partition_key = req.PathParameters["PartitionKey"]; logger.LogLine($"DeleteAlbum: {partition_key}, photosBucket {photosBucket}, thumbnailsBucket {thumbnailsBucket}"); // Get key of the album folder var s3_folder_key = $"public/{partition_key.Substring(0, 4)}/{partition_key.Substring(5)}/"; await Deletes3Folder(photosBucket, s3_folder_key); await Deletes3Folder(thumbnailsBucket, s3_folder_key); // Now delete the dynamodb documents var fullAlbum = await GetAlbumFull(archiveTable, partition_key); var client = new AmazonDynamoDBClient(); List <Task> listOfTasks = new List <Task>(); fullAlbum.Photos.ForEach(ph => { var delRequest = GetDeleteDbRequest(archiveTable, partition_key, "sort_key", ph.SortKey); listOfTasks.Add(client.DeleteItemAsync(delRequest)); }); var delCovReq = GetDeleteDbRequest(archiveTable, partition_key, "sort_key", "alb"); listOfTasks.Add(client.DeleteItemAsync(delCovReq)); await Task.WhenAll(listOfTasks); logger.LogLine("DeleteAlbum completed"); return(new APIGatewayProxyResponse { StatusCode = 200, Headers = new Dictionary <string, string> () { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Credentials", "true" } }, Body = JsonConvert.SerializeObject(new DeleteAlbumResponse { IsSuccess = false, ErrorMessage = "", PartitionKey = partition_key }) }); }
public async Task DeleteById(string userId) { var response = await _dbClient.DeleteItemAsync(TableName, new Dictionary <string, AttributeValue> { { "Id", new AttributeValue(userId) } }); }
// snippet-end:[DynamoDB.dotnetv3.dynamodb-basics.BatchWriteItem] // snippet-start:[DynamoDB.dotnetv3.dynamodb-basics.DeleteItem] /// <summary> /// Deletes a single item from a DynamoDB table. /// </summary> /// <param name="client">The initialized DynamoDB client object.</param> /// <param name="tableName">The name of the table from which the item /// will be deleted.</param> /// <param name="movieToDelete">A movie object containing the title and /// year of the movie to delete.</param> /// <returns>A Boolean value indicating the success or failure of the /// delete operation.</returns> public static async Task <bool> DeleteItemAsync( AmazonDynamoDBClient client, string tableName, Movie movieToDelete) { var key = new Dictionary <string, AttributeValue> { ["title"] = new AttributeValue { S = movieToDelete.Title }, ["year"] = new AttributeValue { N = movieToDelete.Year.ToString() }, }; var request = new DeleteItemRequest { TableName = tableName, Key = key, }; var response = await client.DeleteItemAsync(request); return(response.HttpStatusCode == System.Net.HttpStatusCode.OK); }
public void Delete(long id) { var request = new DeleteItemRequest { TableName = "employee", Key = new Dictionary <string, AttributeValue>() { { "id", new AttributeValue { S = id.ToString() } } }, ReturnValues = new ReturnValue("ALL_OLD"), }; DeleteItemResponse x = dynamodbClient.DeleteItemAsync(request).Result; if (x.HttpStatusCode != System.Net.HttpStatusCode.OK && x.HttpStatusCode != System.Net.HttpStatusCode.OK) { throw new Exception("Unable to delete Employee"); } if (x.Attributes.Count == 0) { throw new KeyNotFoundException("Employee not found"); } return; }
/// <summary> /// Delete an entry from a DynamoDB table /// </summary> /// <param name="tableName">The name of the table to delete an entry</param> /// <param name="keys">The table entry keys for the entry to be deleted</param> /// <param name="conditionExpression">Optional conditional expression</param> /// <param name="conditionValues">Optional field/attribute values used in the conditional expression</param> /// <returns></returns> public Task DeleteEntryAsync(string tableName, Dictionary <string, AttributeValue> keys, string conditionExpression = "", Dictionary <string, AttributeValue> conditionValues = null) { if (Logger.IsVerbose2) { Logger.Verbose2("Deleting table {0} entry with key(s) {1}", tableName, Utils.DictionaryToString(keys)); } try { var request = new DeleteItemRequest { TableName = tableName, Key = keys }; if (!string.IsNullOrWhiteSpace(conditionExpression)) { request.ConditionExpression = conditionExpression; } if (conditionValues != null && conditionValues.Keys.Count > 0) { request.ExpressionAttributeValues = conditionValues; } return(ddbClient.DeleteItemAsync(request)); } catch (Exception exc) { Logger.Warn(ErrorCode.StorageProviderBase, $"Intermediate error deleting entry from the table {tableName}.", exc); throw; } }
public async Task DeleteAsync(string id, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); DeleteItemRequest deleteItem = DynamoDbParser.GetDeleteItemRequest(id); await client.DeleteItemAsync(deleteItem, cancellationToken); }
/** * Invalidate (delete) any access tokens that exist for the specified user. */ internal static async Task InvalidateUserAccessTokens(AmazonDynamoDBClient dbClient, string userId) { Debug.Untested(); Debug.AssertValid(dbClient); Debug.AssertID(userId); Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue>(); key.Add(IdentityServiceDataLayer.FIELD_ACCESS_TOKENS_USER_ID, new AttributeValue(userId)); DeleteItemResponse deleteResponse = await dbClient.DeleteItemAsync(IdentityServiceDataLayer.DATASET_ACCESS_TOKENS_INDEX_USER_ID, key); Debug.AssertValid(deleteResponse); //??++CHECK RESPONSE? //??-- List<string> accessTokens = new List<string>(); // foreach (var item in AccessTokens) { // Debug.AssertValid(item); // Debug.AssertString(item.Key); // Debug.AssertValidOrNull(item.Value); // if (item.Value != null) { // Debug.Assert(item.Value.ID == item.Key); // Debug.AssertValidOrNull(item.Value.User); // if (item.Value.User != null) { // if (item.Value.User.ID == userId) { // accessTokens.Add(item.Key); // } // } // } // } // foreach (var accessToken in accessTokens) { // Debug.AssertString(accessToken); // AccessTokens.Remove(accessToken); // } }
public async static Task <int> MainDeleteAsync(SongDescription DeleteSong) { Dictionary <string, AttributeValue> conditions = new Dictionary <string, AttributeValue>(); if (DeleteSong != null) { if (DeleteSong.Artist != null && DeleteSong.Artist != "") { conditions.Add("Artist", new AttributeValue { S = DeleteSong.Artist }); } if (DeleteSong.SongTitle != null && DeleteSong.SongTitle != "") { conditions.Add("SongTitle", new AttributeValue { S = DeleteSong.SongTitle }); } } DeleteItemRequest request = new DeleteItemRequest { TableName = tableName, Key = conditions }; await client.DeleteItemAsync(request); return(200); }
public async Task <bool> Delete(Guid paymentId) { try { var request = new DeleteItemRequest { TableName = TableName, Key = new Dictionary <string, AttributeValue>() { { "PaymentId", new AttributeValue { S = paymentId.ToString() } } }, // required to check if actual item was deleted ReturnValues = new ReturnValue("ALL_OLD") }; var result = await _client.DeleteItemAsync(request); // With ALL_OLD document is returned in attributes - if it was deleted then attributes colleciton wont be empty return(result.Attributes.Count > 0); } catch (System.Exception ex) { throw; } }
public void DeleteItem(string PrimaryKeyID, string TableName) { try { context.Logger.LogLine("DynamoDBHelper::DeleteItem()=> TableName = " + TableName); context.Logger.LogLine("DynamoDBHelper::DeleteItem()=> PKID = " + PrimaryKeyID); Table table = Table.LoadTable(client, TableName); Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue> { { "PrimaryKeyID1", new AttributeValue { S = PrimaryKeyID } } }; // Create DeleteItem request DeleteItemRequest request = new DeleteItemRequest { TableName = TableName, Key = key }; // Issue request client.DeleteItemAsync(request).GetAwaiter().GetResult(); context.Logger.LogLine("DynamoDBHelper::DeleteItem() -- Delete Operation succeeded"); } catch (Exception ex) { context.Logger.LogLine("DynamoDBHelper::DeleteItem() -- " + ex.Message); context.Logger.LogLine("DynamoDBHelper::DeleteItem() -- " + ex.StackTrace); } }
private void DeleteTrack(string bucket, string trackName) { //if the image exists we assume the data in the db and track files exist. AwsS3Utility.DeleteObject(bucket, trackName + ".jpg", RegionEndpoint.USEast1); AwsS3Utility.DeleteObject(bucket, trackName + ".zip", RegionEndpoint.USEast1); AwsS3Utility.DeleteObject(bucket, trackName + ".rar", RegionEndpoint.USEast1); try { //Remove from db AmazonDynamoDBClient client = new AmazonDynamoDBClient(RegionEndpoint.USEast1); string tableName = "ReflexTracks"; var request = new DeleteItemRequest { TableName = tableName, Key = new Dictionary <string, AttributeValue>() { { "TrackName", new AttributeValue { S = trackName } } }, }; client.DeleteItemAsync(request).Wait(); } catch (Exception e) { Console.WriteLine("Error deleting track from database: " + e.Message); } }
public static async Task DeleteItemAsync() { #region service_client_delete using (var ddbClient = new AmazonDynamoDBClient()) { var request = new DeleteItemRequest { TableName = "TODOList", Key = new Dictionary <string, AttributeValue> { { "User", new AttributeValue { S = "serviceclient-testuser" } }, { "ListId", new AttributeValue { S = "generated-list-id" } } } }; var response = await ddbClient.DeleteItemAsync(request); Console.WriteLine("Item Deleted"); } #endregion }
public async Task ReleaseLock(string Id) { if (_mutex.WaitOne()) { try { _localLocks.Remove(Id); } finally { _mutex.Set(); } } try { var req = new DeleteItemRequest() { TableName = _tableName, Key = new Dictionary <string, AttributeValue> { { "id", new AttributeValue(Id) } }, ConditionExpression = "lock_owner = :nodeId", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":nodeId", new AttributeValue(_nodeId) } } }; await _client.DeleteItemAsync(req); } catch (ConditionalCheckFailedException) { } }
private async Task DeletePodcastPlaybackAsync(string userId) { var response = await _dynamoClient.DeleteItemAsync(_dynamoTable, new Dictionary <string, AttributeValue> { ["Key"] = new AttributeValue { S = UserIdToResumeRecordKey(userId) } }); }
public async Task <DeleteItemResponse> DeleteUser(string userId) { return(await _dynamoClient.DeleteItemAsync(new DeleteItemRequest(DynamoConstants.CREDENTIALS_TABLE, new Dictionary <string, AttributeValue> { { DynamoConstants.UserIdKey, new AttributeValue(userId) } }))); }
internal static async Task <DeleteItemResponse> Build <Item>(Item item, string tableName, ItemConverter <Item> itemConverter, AmazonDynamoDBClient dynamodbClient) { DeleteItemRequest deleteItemRequest = new DeleteItemRequest() { TableName = tableName, Key = itemConverter.GetItemAsAttributes(item) }; return(await dynamodbClient.DeleteItemAsync(deleteItemRequest)); }
public async Task <DeleteItemResponse> DeleteItemAsync(string pk, string sk) { await SetLastUpdateAsync(); using var client = new AmazonDynamoDBClient(); var key = GetKey(pk, sk); var deleteItemRequest = new DeleteItemRequest(TABLE_NAME, key); var deleteItemResponse = await client.DeleteItemAsync(deleteItemRequest); return(deleteItemResponse); }
public bool DeleteQuote(string quotee, string quoteText) { return(_db.DeleteItemAsync(new DeleteItemRequest { TableName = TableName, Key = { ["Quotee"] = new AttributeValue(quotee), ["Quote"] = new AttributeValue(quoteText) } }).Result.HttpStatusCode == System.Net.HttpStatusCode.OK); }
public async Task TerminateSubscription(string eventSubscriptionId) { var request = new DeleteItemRequest() { TableName = $"{_tablePrefix}-{SUBCRIPTION_TABLE}", Key = new Dictionary <string, AttributeValue> { { "id", new AttributeValue(eventSubscriptionId) } } }; await _client.DeleteItemAsync(request); }
public async Task <bool> RemoveAsync <TKey>(TKey key) { var request = new DeleteItemRequest { TableName = _tableName, Key = SetKeyItems(key), ReturnValues = ReturnValue.ALL_OLD, }; var response = await _dynamoDBClient.DeleteItemAsync(request).ConfigureAwait(false); return(response.Attributes.Any()); }
public Task <DeleteItemResponse> DeleteItemAsync(DeleteItemRequest request, CancellationToken cancellationToken = default) { Guard.ArgumentNotNull(request, "request can not be null"); try { AmazonDynamoDBClient client = GetAmazonDynamoDbClient(); var result = client.DeleteItemAsync(request); return(result); } catch (AmazonDynamoDBException ex) { throw ex; } }
public async Task FunctionHandler(DynamoDBEvent dynamoEvent, ILambdaContext context) { context.Logger.LogLine($"Beginning to process {dynamoEvent.Records.Count} records..."); bool containsInsertRecord = false; //Search for an insert record foreach (var record in dynamoEvent.Records) { if (record.EventName == "INSERT") { containsInsertRecord = true; break; } } if (containsInsertRecord) { var dynamoDbClient = new AmazonDynamoDBClient(RegionEndpoint.USEast1); var dynamoContext = new DynamoDBContext(dynamoDbClient); long currentTime = TimeUtility.DateTimeToUnixTimeStamp(DateTime.UtcNow); long expiredTime = currentTime - (TrackSharing.LifeSpanMinutes * 60); context.Logger.LogLine($"Looking for records older than {expiredTime}"); var exipredItems = new List <ScanCondition>() { new ScanCondition("CreationTime", ScanOperator.LessThanOrEqual, expiredTime) }; var expiredItems = await dynamoContext.ScanAsync <TrackList>(exipredItems).GetRemainingAsync(); foreach (var trackSet in expiredItems) { context.Logger.LogLine($"Deleting {trackSet.Name}..."); var request = new DeleteItemRequest { TableName = "SharedReflexTrackLists", Key = new Dictionary <string, AttributeValue>() { { "Name", new AttributeValue { S = trackSet.Name } } }, }; var response = await dynamoDbClient.DeleteItemAsync(request); } } context.Logger.LogLine("Stream processing complete."); }
public async Task <IActionResult> DeleteTitle(string isbn) { await DynamoDbClient.DeleteItemAsync(TitlesTable, new Dictionary <string, AttributeValue> { { "isbn", new AttributeValue(isbn) } }); await SqsClient.SendMessageAsync(TitlesQueue, JsonConvert.SerializeObject(new { EventType = "DELETE", Payload = new { isbn }, }, JsonSerializerSettings)); return(Ok()); }
protected override async Task InternalRemove(string normalizedWord) { using var dyCli = new AmazonDynamoDBClient(); await dyCli.DeleteItemAsync(new DeleteItemRequest("WordsTable", new Dictionary <string, AttributeValue>( new Dictionary <string, AttributeValue> { { "Word", new AttributeValue { S = normalizedWord } } } ) ) ); }
public Task <DeleteItemResponse> DeleteItemAsync(string tableName, Dictionary <string, AttributeValue> key, ReturnValue returnValues, CancellationToken cancellationToken = default) { Guard.ArgumentNotNullOrWhiteSpace(tableName, "tableName can not be null"); Guard.ArgumentNotNull(key, "key can not be null"); Guard.ArgumentNotNull(returnValues, "returnValues can not be null"); try { AmazonDynamoDBClient client = GetAmazonDynamoDbClient(); var result = client.DeleteItemAsync(tableName, key, returnValues); return(result); } catch (AmazonDynamoDBException ex) { throw ex; } }
private void Delete(Song song) { try { var items = new Dictionary <string, AttributeValue> { { "SongId", new AttributeValue { N = song.SongId.ToString() } } }; var response = _db.DeleteItemAsync("SongQueue", items).Result; } catch (Exception e) { throw new Exception($"Failed to delete song ({song}) from queue to DynamoDb.", e); } }
public static async void DeleteItem(AmazonDynamoDBClient client, string partitionKey, string sortKey) { var request = new DeleteItemRequest { TableName = _tableName, Key = new Dictionary <string, AttributeValue>() { { "Id", new AttributeValue { S = partitionKey } }, { "ReplyDateTime", new AttributeValue { S = sortKey } } } }; await client.DeleteItemAsync(request); }
public void delete(string connectionId) { DeleteItemRequest request = new DeleteItemRequest { TableName = connectionTableName, Key = new Dictionary <string, AttributeValue>() { { "ConnectionId", new AttributeValue { S = connectionId } } } }; var response = amazonDynamoDbClient.DeleteItemAsync(request); response.Wait(); }
private async void DeleteItem() { AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsCredentials, awsRegion); Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue> { { "Id", new AttributeValue { N = "10" } } }; DeleteItemRequest request = new DeleteItemRequest { TableName = "Books", Key = key }; var response = await client.DeleteItemAsync(request); }
public void Delete(string connectionId) { ScanRequest scanRequest = new ScanRequest() { TableName = "Connection", FilterExpression = "ConnectionId = :ConnectionId", ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { { ":ConnectionId", new AttributeValue() { S = connectionId } } } }; var scanResponse = DbClient.ScanAsync(scanRequest); scanResponse.Wait(); DeleteItemRequest request = new DeleteItemRequest { TableName = ConnectionTableName, Key = new Dictionary <string, AttributeValue>() { { "ContractId", new AttributeValue { S = scanResponse.Result.Items[0]["ContractId"].S } }, { "ConnectionId", new AttributeValue { S = connectionId } } } }; var response = DbClient.DeleteItemAsync(request); response.Wait(); }