private static IAmazonDynamoDB GetDynamoDbClient(string choice) { if (string.IsNullOrWhiteSpace(choice) == false && choice.Trim().ToLower() == "y") { try { // here we use the IAM Role attached to the EC2 instance to get the credentials return(new AmazonDynamoDBClient(RegionEndpoint.USWest2)); } catch (Exception ex) { WriteLine(ConsoleColor.Red, ex.Message); return(null); } } var config = new AmazonDynamoDBConfig() { RegionEndpoint = RegionEndpoint.USWest2 }; var client = AWSClientFactory.CreateAmazonDynamoDBClient( AccessKey, SecretKey, config ); return(client); }
/// <summary> /// This method will show where the session state data is stored in Amazon DynamoDB. /// This is just for demonstration purposes and normal use of the session is done /// through the Context.Session property. /// </summary> private void InspectSessionTable() { using (StringWriter sr = new StringWriter()) { try { var dynamoDb = AWSClientFactory.CreateAmazonDynamoDBClient(RegionEndpoint.USWest2); var table = Table.LoadTable(dynamoDb, "ASP.NET_SessionState"); sr.WriteLine("<li>Table: {0}</li>", table.TableName); sr.WriteLine("<li>Hash Key: {0}</li>", table.HashKeys[0]); var item = table.GetItem(this.Context.Session.SessionID); if (item == null || !item.Contains(DynamoDBSessionStateStore.ATTRIBUTE_CREATE_DATE)) { sr.WriteLine("<li>Session Not Persisted Yet</li>"); } else { sr.WriteLine("<li>Session Created: {0}</li>", (DateTime)item[DynamoDBSessionStateStore.ATTRIBUTE_CREATE_DATE]); sr.WriteLine("<li>Session Expires: {0}</li>", (DateTime)item[DynamoDBSessionStateStore.ATTRIBUTE_EXPIRES]); } } catch (AmazonDynamoDBException ex) { if (ex.ErrorCode != null && ex.ErrorCode.Equals("AuthFailure")) { sr.WriteLine("The account you are using is not signed up for Amazon DynamoDB."); sr.WriteLine("<br />"); sr.WriteLine("You can sign up for Amazon DynamoDB at http://aws.amazon.com/dynamodb/"); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } else { sr.WriteLine("Caught Exception: " + ex.Message); sr.WriteLine("<br />"); sr.WriteLine("Response Status Code: " + ex.StatusCode); sr.WriteLine("<br />"); sr.WriteLine("Error Code: " + ex.ErrorCode); sr.WriteLine("<br />"); sr.WriteLine("Error Type: " + ex.ErrorType); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } } this.dynamoDBPlaceholder.Text = sr.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { // Get the SMS details from the Request and pit them into a dictionary // ready to insert into Dynamo DB. Dictionary <string, AttributeValue> messageDetails = new Dictionary <string, AttributeValue>(); messageDetails.Add("ID", new AttributeValue(Request["MessageSid"])); messageDetails.Add("From", new AttributeValue(Request["From"])); messageDetails.Add("Body", new AttributeValue(Request["Body"])); // Create the client to be used to write to Dynamo DB. // Use the preview endpoint so that we can make use of DynamoDb Streams to trigger // lambda functions. var config = new AmazonDynamoDBConfig(); config.ServiceURL = "https://preview-dynamodb.us-east-1.amazonaws.com"; IAmazonDynamoDB client = AWSClientFactory.CreateAmazonDynamoDBClient(config); // Add the SMS received to the Dynamo Db table, client.PutItem("SmsMessages", messageDetails); }
public DynamoDBClient() { var aws = CManager.Settings.AWS; _service = AWSClientFactory.CreateAmazonDynamoDBClient(aws.AccessKey, aws.SecretAccessKey, RegionEndpoint.GetBySystemName(aws.RegionEndpoint)); }
public static IAmazonDynamoDB GetDynamoDbClient() { return(AWSClientFactory.CreateAmazonDynamoDBClient(GetAwsCredentials(), DynamoDbRegion)); }