private async Task SaveNewItem() { Guid ClientGuidid = Guid.NewGuid(); Guid SecretGuidid = Guid.NewGuid(); await client.PutItemAsync( tableName : ClientTableName, item : new Dictionary <string, AttributeValue> { { "ClientID", new AttributeValue { S = email } }, { "Appliance", new AttributeValue { SS = appliance } }, { "Amazn_link_time", new AttributeValue { S = " " } }, { "ActiveStatus", new AttributeValue { BOOL = clientStatus } }, { "ClientGuid", new AttributeValue { S = ClientGuidid.ToString() } }, { "secret", new AttributeValue { S = SecretGuidid.ToString() } } } ); }
// called by UIManager void UploadLevel(string jsonFile, DevEditorData levelData) { Debug.Log("Craeting new Request"); var request = new PutItemRequest { TableName = CommunityDatabase.tableName, Item = new Dictionary <string, AttributeValue>() { { CommunityDatabase.baseTablePK, new AttributeValue { S = "12345" } }, { CommunityDatabase.baseTableSK, new AttributeValue { S = levelData.levelName } }, { CommunityDatabase.levelFile, new AttributeValue { S = jsonFile } }, { CommunityDatabase.publishDate, new AttributeValue { S = DateTime.Today.ToShortDateString() } }, // { CommunityDatabase.creatorSetDifficulty, new AttributeValue{ S = ""} } }; Debug.Log("Uploading " + levelData.levelName); client.PutItemAsync(request); var response = client.PutItemAsync(request); if (response.Exception != null) { Debug.Log(response.Exception.Message); } }
public async Task AddAsync <TKey, TValue>(TKey key, TValue value) { var request = new PutItemRequest { TableName = _tableName, Item = SetKeyItems(key, new Dictionary <string, AttributeValue> { { "Value", AttributeValueTypeAccessor <TValue> .CreateValue(value, _settings.Serializer) }, }), Expected = new Dictionary <string, ExpectedAttributeValue> { { "Dictionary", new ExpectedAttributeValue(false) }, { "Key", new ExpectedAttributeValue(false) }, } }; try { var response = await _dynamoDBClient.PutItemAsync(request).ConfigureAwait(false); } catch (ConditionalCheckFailedException ex) { throw new ArgumentException("An item with the same key has already been added.", ex); } }
private void InsertIntoTables() { var request = new PutItemRequest() { TableName = "Contract", Item = new Dictionary <string, AttributeValue>() { { "ContractId", new AttributeValue("A100") }, { "BuyingPower", new AttributeValue() { N = "10000" } } } }; var result = DbClient.PutItemAsync(request); result.Wait(); request = new PutItemRequest() { TableName = "Assets", Item = new Dictionary <string, AttributeValue>() { { "ContractId", new AttributeValue() { S = "A100" } }, { "InstrumentId", new AttributeValue() { N = "1003232" } }, { "Quantity", new AttributeValue() { N = "10" } }, { "AveragePrice", new AttributeValue() { N = "1000" } }, { "LastPrice", new AttributeValue() { N = "1000" } }, { "ClosePrice", new AttributeValue() { N = "1000" } } } }; result = DbClient.PutItemAsync(request); result.Wait(); }
public async Task <string> CreateNewWorkflow(WorkflowInstance workflow) { workflow.Id = Guid.NewGuid().ToString(); var req = new PutItemRequest() { TableName = $"{_tablePrefix}-{WORKFLOW_TABLE}", Item = workflow.ToDynamoMap(), ConditionExpression = "attribute_not_exists(id)" }; var response = await _client.PutItemAsync(req); return(workflow.Id); }
public async Task <bool> Write(Widget widget) { try { AmazonDynamoDBClient client = new AmazonDynamoDBClient(_credentials, _region); var request = new PutItemRequest() { TableName = TableName, Item = new Dictionary <string, AttributeValue>() { { "pk", new AttributeValue { S = widget.pk } }, { "sk", new AttributeValue { S = widget.sk } }, { "data", new AttributeValue { S = widget.data } } } }; await client.PutItemAsync(request); return(true); } catch (Exception e) { Console.WriteLine("ERROR " + e.Message); return(false); } }
private void SaveToDb(Song song) { try { var items = new Dictionary <string, AttributeValue> { { "SongId", new AttributeValue { N = song.SongId.ToString() } }, { "SongRef", new AttributeValue { S = song.SongRef.ToString() } }, { "Artist", new AttributeValue { S = song.Artist } }, { "Album", new AttributeValue { S = song.Album } }, { "Title", new AttributeValue { S = song.Title } }, { "Track", new AttributeValue { N = song.Track.ToString() } }, { "FilePath", new AttributeValue { S = song.FilePath } } }; var response = _db.PutItemAsync(new PutItemRequest("Songs", items)).Result; } catch (Exception e) { throw new Exception($"Failed to save song ({song}) to DynamoDb.", e); } }
public static void CreateItem(AmazonDynamoDBClient client) { var request = new PutItemRequest { TableName = _tableName, Item = new Dictionary <string, AttributeValue>() { { "Id", new AttributeValue { N = "1000" } }, { "Title", new AttributeValue { S = "Book 201 Title" } }, { "ISBN", new AttributeValue { S = "11-11-11-11" } }, { "Authors", new AttributeValue { SS = new List <string> { "Author1", "Author2" } } }, { "Price", new AttributeValue { N = "20.00" } }, { "Dimensions", new AttributeValue { S = "8.5x11.0x.75" } }, { "InPublication", new AttributeValue { BOOL = false } } } }; client.PutItemAsync(request); }
/// <summary> /// Method to insert data into DynamoDB /// </summary> /// <param name="tableName"></param> /// <returns>True if data is inserted</returns> public bool FuncInsertData(string tableName) { bool IsInserted = false; try { PutItemRequest request1 = new PutItemRequest { TableName = tableName, Item = new Dictionary <string, AttributeValue> { { "KEY", new AttributeValue { S = "2" } }, { "TYPE", new AttributeValue { S = "23" } }, { "VALUE", new AttributeValue { S = "Sample" } } } }; client.PutItemAsync(request1); IsInserted = true; return(IsInserted); } catch (Exception) { return(IsInserted); } }
private async Task InsertNewRequest(string prNumber, string status, string jobId, string jobStatus) { LambdaLogger.Log($"Insert New Request"); var putItemRequest = new PutItemRequest { TableName = _tablename, Item = new Dictionary <string, AttributeValue> { { "pr", new AttributeValue { S = prNumber } }, { "testStatus", new AttributeValue { S = status } }, { "jobId", new AttributeValue { S = jobId } }, { "jobStatus", new AttributeValue { S = jobStatus } } } }; var table = await _amazonDynamoDBclient.PutItemAsync(putItemRequest); }
private async Task RegisterVisit(string locationId, string locationName, string fullName, string phone) { var timestamp = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff"); var request = new PutItemRequest { TableName = REGISTRATIONS_TABLE_NAME, Item = new Dictionary <string, AttributeValue> { { "locationId", new AttributeValue { S = locationId } }, { "locationName", new AttributeValue { S = locationName } }, { "visitId", new AttributeValue { S = $"{phone}-{timestamp}" } }, { "timestamp", new AttributeValue { N = timestamp } }, { "fullName", new AttributeValue { S = fullName } }, { "phone", new AttributeValue { S = phone } } } }; await _dynamoDbClient.PutItemAsync(request); }
public bool UpdateContent(ContentEntity content) { AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig(); clientConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfig); Dictionary <string, AttributeValue> item = new Dictionary <string, AttributeValue>(); item["ContentKey"] = new AttributeValue() { S = content.ContentKey }; item["Content"] = new AttributeValue() { S = "<p>" + content.ContentHtml + "</p>" }; PutItemRequest request = new PutItemRequest() { TableName = TABLE_NAME, Item = item }; try { var response = client.PutItemAsync(request); return(response.Result.HttpStatusCode == HttpStatusCode.OK); } catch (Exception ex) { return(false); } }
public async Task SaveToDatabase(string shardId, string sequenceNumber, DateTime lastUpdateUtc) { if (!_tableExists) { Log.Error("The DynamoDB checkpoint table doesn't exist."); return; } var putItemRequest = new PutItemRequest { TableName = TableName }; putItemRequest.Item.Add("Id", new AttributeValue(string.Format(KeyIdPattern, shardId, _utilities.WorkerId, _utilities.StreamName))); putItemRequest.Item.Add("ShardId", new AttributeValue(shardId)); if (!string.IsNullOrEmpty(sequenceNumber)) { putItemRequest.Item.Add("SequenceNumber", new AttributeValue(sequenceNumber)); } putItemRequest.Item.Add("LastUpdate", new AttributeValue(lastUpdateUtc.ToString())); try { await _client.PutItemAsync(putItemRequest); } catch (Exception e) { Debug.WriteLine(e.InnerException); } }
private async Task StoreAdventureState(AdventureState state) { if (_adventurePlayerTable != null) { var jsonState = JsonConvert.SerializeObject(state, Formatting.None); LogInfo($"storing state in player table\n{jsonState}"); await _dynamoClient.PutItemAsync(_adventurePlayerTable, new Dictionary <string, AttributeValue> { ["PlayerId"] = new AttributeValue { S = state.RecordId }, ["State"] = new AttributeValue { S = jsonState }, ["Expire"] = new AttributeValue { N = ToEpoch(DateTime.UtcNow.AddDays(30)).ToString() } }); } // local functions uint ToEpoch(DateTime date) { return((uint)date.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds); } }
public static async Task <bool> CreateItem(AmazonDynamoDBClient client, string partitionKey, string sortKey) { MemoryStream compressedMessage = ToGzipMemoryStream("Some long extended message to compress."); var request = new PutItemRequest { TableName = _tableName, Item = new Dictionary <string, AttributeValue>() { { "Id", new AttributeValue { S = partitionKey } }, { "ReplyDateTime", new AttributeValue { S = sortKey } }, { "Subject", new AttributeValue { S = "Binary type " } }, { "Message", new AttributeValue { S = "Some message about the binary type" } }, { "ExtendedMessage", new AttributeValue { B = compressedMessage } } } }; await client.PutItemAsync(request); return(true); }
public void Add(Employee employee) { var request = new PutItemRequest { TableName = "employee", Item = new Dictionary <string, AttributeValue> { { "id", new AttributeValue { S = DateTime.Now.Ticks.ToString() } }, { "name", new AttributeValue { S = employee.name } }, { "email", new AttributeValue { S = employee.email } }, { "department", new AttributeValue { S = employee.department } } } }; PutItemResponse x = dynamodbClient.PutItemAsync(request).Result; if (x.HttpStatusCode != System.Net.HttpStatusCode.OK && x.HttpStatusCode != System.Net.HttpStatusCode.OK) { throw new Exception("Unable to add Employee"); } return; }
public async Task <Task <PutItemResponse> > AddMessage(Message messageDb) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); var request = new PutItemRequest { TableName = TableName, Item = new Dictionary <string, AttributeValue>() { { "sender_id", new AttributeValue { N = messageDb.sender_id.ToString() } }, { "datetime", new AttributeValue { S = messageDb.datetime.Replace("/", "-") } }, { "sender_name", new AttributeValue { S = messageDb.sender_name } }, { "message", new AttributeValue { S = messageDb.message } }, { "info", new AttributeValue { SS = messageDb.info } } } }; return(client.PutItemAsync(request)); //await _context.SaveAsync(messageDb); }
/// <summary> /// Create or Replace an entry in a DynamoDB Table /// </summary> /// <param name="tableName">The name of the table to put an entry</param> /// <param name="fields">The fields/attributes to add or replace in the table</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 PutEntryAsync(string tableName, Dictionary <string, AttributeValue> fields, string conditionExpression = "", Dictionary <string, AttributeValue> conditionValues = null) { if (Logger.IsVerbose2) { Logger.Verbose2("Creating {0} table entry: {1}", tableName, Utils.DictionaryToString(fields)); } try { var request = new PutItemRequest(tableName, fields, ReturnValue.NONE); if (!string.IsNullOrWhiteSpace(conditionExpression)) { request.ConditionExpression = conditionExpression; } if (conditionValues != null && conditionValues.Keys.Count > 0) { request.ExpressionAttributeValues = conditionValues; } return(ddbClient.PutItemAsync(request)); } catch (Exception exc) { Logger.Error(ErrorCode.StorageProviderBase, $"Unable to create item to table '{tableName}'", exc); throw; } }
public dynamic handler(dynamic eventTrigger) { Console.WriteLine(eventTrigger); AmazonDynamoDBClient client = new AmazonDynamoDBClient(); var tableName = Environment.GetEnvironmentVariable("TABLE_NAME"); // get the table name from the automatically populated environment variables var id = "1"; // modify with each invoke so the id does not repeat var content = "This is my content"; // modify content here Console.WriteLine("Adding item " + id + " to table " + tableName); // Write a new item to the Item table var request = new PutItemRequest() { TableName = tableName, Item = new Dictionary <string, AttributeValue>() { { "id", new AttributeValue { S = id } }, { "content", new AttributeValue { S = content } } } }; var response = client.PutItemAsync(request).Result; Console.WriteLine("Item added to table, done!"); return(response); }
public PutItemResponse AddKills(MobKillsLog killsLog) { var tableName = "MobKillsLog"; var request = new PutItemRequest { TableName = tableName, Item = new Dictionary <string, AttributeValue> { { "id", new AttributeValue { S = killsLog.Id } }, { "mobid", new AttributeValue { S = killsLog.MobId } }, { "playerid", new AttributeValue { S = killsLog.PlayerId } }, { "timestamp", new AttributeValue { S = killsLog.TimeStamp } } } }; return(_client.PutItemAsync(request).Result); }
public async Task <bool> PutSecret(string secret, string challenge, string address, string fileHash) { var request = new PutItemRequest { TableName = tableName, Item = new Dictionary <string, AttributeValue>() { { columnSecret, new AttributeValue { S = secret } }, { columnChallenge, new AttributeValue { S = challenge } }, { columnAddress, new AttributeValue { S = address } }, { columnFileHash, new AttributeValue { S = fileHash } } } }; PutItemResponse dynamoDbResponse = await _client.PutItemAsync(request); return(dynamoDbResponse.HttpStatusCode == System.Net.HttpStatusCode.OK); }
/** * Add a ticket price audit record. */ private static async void AddCountryAudit(AmazonDynamoDBClient dbClient, string loggedInUserId, CountryAuditRecord.AuditChangeType changeType, Country country) { Debug.Tested(); Debug.AssertValid(dbClient); Debug.AssertID(loggedInUserId); Debug.AssertValid(country); Dictionary <string, AttributeValue> item = new Dictionary <string, AttributeValue>(); string id = RandomHelper.Next(); item.Add(FIELD_COUNTRY_AUDIT_ID, new AttributeValue(id)); item.Add(FIELD_COUNTRY_AUDIT_TIMESTAMP, new AttributeValue(APIHelper.APITimestampStringFromDateTime(DateTime.Now))); item.Add(FIELD_COUNTRY_AUDIT_ADMINISTRATOR_ID, new AttributeValue(loggedInUserId)); item.Add(FIELD_COUNTRY_AUDIT_CHANGE_TYPE, new AttributeValue { N = changeType.ToString() }); item.Add(FIELD_COUNTRY_AUDIT_CODE, new AttributeValue(country.Code)); item.Add(FIELD_COUNTRY_AUDIT_NAME, new AttributeValue(country.Name)); item.Add(FIELD_COUNTRY_AUDIT_CURRENCIES, new AttributeValue(country.Currencies)); item.Add(FIELD_COUNTRY_AUDIT_AVAILABLE, new AttributeValue { BOOL = country.Available }); PutItemResponse response = await dbClient.PutItemAsync(DATASET_COUNTRY_AUDIT, item); Debug.AssertValid(response); //??++CHECK RESPONSE? }
public void Add(string connectionId, string contractId) { Console.WriteLine(DateTime.Now); PutItemRequest request = new PutItemRequest { TableName = ConnectionTableName, Item = new Dictionary <string, AttributeValue>() { { "ContractId", new AttributeValue { S = contractId } }, { "ConnectionId", new AttributeValue { S = connectionId } } } }; var response = DbClient.PutItemAsync(request); response.Wait(); Console.WriteLine(DateTime.Now); }
public async Task LogStateAsync(Workflow workflow) { var putItemRequest = new PutItemRequest(); putItemRequest.Item = new Dictionary <string, AttributeValue>(); putItemRequest.Item = new Dictionary <string, AttributeValue>(); putItemRequest.Item.Add(Constants.LAMBDA_BIZ_ORCHESTRATION_ID, new AttributeValue { S = workflow.OrchestrationId }); foreach (var activity in workflow.Activities) { if (activity.Name != Constants.LAMBDA_BIZ_EVENT) { putItemRequest.Item.Add(activity.UniqueId, new AttributeValue { S = JsonConvert.SerializeObject(activity) }); } } putItemRequest.Item.Add(Constants.LAMBDA_BIZ_WF_ATTRIBUTES, new AttributeValue { S = workflow.ToString() }); putItemRequest.TableName = Constants.LAMBDA_BIZ_DYNAMODB_TABLE; await _amazonDynamoDbClient.PutItemAsync(putItemRequest); }
public static async Task PutItem() { var request = new PutItemRequest { TableName = "ProductCatalog", Item = new Dictionary <string, AttributeValue> { { "Id", new AttributeValue { N = "100" } }, { "Title", new AttributeValue { S = "Rom Jul" } }, { "ISBN", new AttributeValue { S = "123456789" } }, { "Price", new AttributeValue { S = "900.00" } }, { "Authors", new AttributeValue { SS = new List <string> { "Evan", "akshay" } } } } }; await client.PutItemAsync(request); }
//Function Handler is an entry point to start execution of Lambda Function. //It takes Input Data as First Parameter and ObjectContext as Second public async Task FunctionHandler(Customer customer, ILambdaContext context) { //Write Log to Cloud Watch using Console.WriteLline. Console.WriteLine("Execution started for function - {0} at {1}", context.FunctionName, DateTime.Now); // Create dynamodb client var dynamoDbClient = new AmazonDynamoDBClient( new BasicAWSCredentials(_accessKey, _secretKey), new AmazonDynamoDBConfig { ServiceURL = _serviceUrl, RegionEndpoint = RegionEndpoint.APSoutheast2 }); //Create Table if it Does Not Exists await CreateTable(dynamoDbClient, TableName); // Insert record in dynamodbtable LambdaLogger.Log("Insert record in the table"); await dynamoDbClient.PutItemAsync(TableName, new Dictionary <string, AttributeValue> { { "Name", new AttributeValue(customer.Name) }, { "EmailId", new AttributeValue(customer.EmailId) }, }); //Write Log to cloud watch using context.Logger.Log Method context.Logger.Log(string.Format("Finished execution for function -- {0} at {1}", context.FunctionName, DateTime.Now)); }
public static System.Threading.Tasks.Task <PutItemResponse> putItemAsync(AmazonDynamoDBClient amazonDynamoDBClient, string srnNumber, string entity, string json_value) { try { string strTableName = "StudentDetails"; var request = new PutItemRequest { TableName = strTableName, Item = new Dictionary <string, AttributeValue>() { { "StudentSRN", new AttributeValue { S = srnNumber } }, { entity, new AttributeValue { S = json_value } } }, }; return(amazonDynamoDBClient.PutItemAsync(request)); } catch (Exception ex) { throw ex; } }
private async Task SendToDynamoDb(CartMessage cartMessage, Invoice invoiceApiPayload) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); string tableName = WorkerConfig.DynamoTransactionRegisterTableName; _logger.LogInformation("Sendig transaction register do DynamoDB"); var request = new PutItemRequest { TableName = tableName, Item = new Dictionary <string, AttributeValue>() { { "cartId", new AttributeValue { S = invoiceApiPayload.Id } }, { "amount", new AttributeValue { N = invoiceApiPayload.Total.Amount.ToString() } }, { "scale", new AttributeValue { N = invoiceApiPayload.Total.Scale.ToString() } }, { "currencyCode", new AttributeValue { S = invoiceApiPayload.Total.CurrencyCode } }, { "x-team-control", new AttributeValue { S = cartMessage.Invoice.XTeamControl } }, { "timestamp", new AttributeValue { S = DateTime.Now.ToString() } }, } }; await client.PutItemAsync(request); }
private async Task SaveImageToDynamoDb(string jsonPayload) { AmazonDynamoDBConfig ddbConfig = new AmazonDynamoDBConfig(); ddbConfig.ServiceURL = "http://34.246.18.10:8000"; AmazonDynamoDBClient amazonDynamoDbClient = new AmazonDynamoDBClient(ddbConfig); var twitterObject = JsonConvert.DeserializeObject <TwitterStreamModel>(jsonPayload); if (twitterObject.extended_entities.media.Count > 0) { foreach (var media in twitterObject.extended_entities.media) { try { //Download Image WebClient client = new WebClient(); var memoryStream = new MemoryStream(); System.IO.Stream stream = client.OpenRead(media.media_url); CopyStream(stream, memoryStream); if (memoryStream.Length > 0) { // Define item attributes Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); // hash-key attributes["id"] = new AttributeValue { S = twitterObject.id }; // range-key attributes["reference"] = new AttributeValue { S = media.media_url }; // Binary Data for Image attributes["streamdata"] = new AttributeValue { B = memoryStream }; var swStoreImage = Stopwatch.StartNew(); var response = await amazonDynamoDbClient.PutItemAsync(new PutItemRequest { TableName = "twitter-stream-data-image", Item = attributes }).ConfigureAwait(false); swStoreImage.Stop(); Console.WriteLine($"Store Image {media.media_url} for Id: {twitterObject.id} time {swStoreImage.ElapsedMilliseconds} ms"); } } catch (Exception e) { Console.WriteLine(e.Message); } } } }
public bool AddQuote(Quote quote) { return(_db.PutItemAsync(new PutItemRequest { TableName = TableName, Item = PrepareQuote(quote) }).Result.HttpStatusCode == System.Net.HttpStatusCode.OK); }