List of usage examples for com.amazonaws.services.dynamodbv2.document DynamoDB DynamoDB
public DynamoDB(Regions regionEnum)
From source file:AddUserPassword.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("UserLogin"); int UserID = 0; String UserName = "Patrick Laflin"; int UserPassword = 18924; try {//from ww w . j a v a 2 s . c o m System.out.println("Adding a new item..."); PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("UserID", UserID) .withString("User Name", UserName).withNumber("User Password", UserPassword)); System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult()); } catch (Exception e) { System.err.println("Unable to add item: " + UserID + " " + UserName); System.err.println(e.getMessage()); } }
From source file:NYSEScan.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration */// w w w . j a va 2 s . co m private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (/Users/usdgadiraj/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/usdgadiraj/.aws/credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region region = Region.getRegion(Regions.US_EAST_1); dynamoDB.setRegion(region); dynamoDB.setEndpoint("http://dynamo.itversity.com:8000"); dynamo = new DynamoDB(dynamoDB); }
From source file:CreateUserLoginTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserLogin"; try {/*from w ww . j a v a2 s . co m*/ System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:CreateUserFavoritesTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserFavorites"; try {//from w w w .ja v a 2 s . co m System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:AddUserInfo.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("UserInfo"); int UserID = 0; String FirstName = "Patrick"; String LastName = "Laflin"; String PhoneNumber = "(850)276-3816"; String StreetAddressLine1 = "118 E Lakeshore Drive"; String StreetAddressLine2 = "Unit B"; String City = "Panama City Beach"; String State = "FL"; int ZipCode = 32413; String EmailAddress = "pbl14@my.fsu.edu"; try {/*from ww w . j a v a 2 s . co m*/ System.out.println("Adding a new item..."); PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("UserID", UserID) .withString("First Name", FirstName).withString("Last Name", LastName) .withString("Phone Number", PhoneNumber).withString("Street Address Line 1", StreetAddressLine1) .withString("Street Address Line 2", StreetAddressLine2).withString("City", City) .withString("State", State).withNumber("Zip Code", ZipCode) .withString("Email Address", EmailAddress)); System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult()); } catch (Exception e) { System.err.println("Unable to add item: " + UserID); System.err.println(e.getMessage()); } }
From source file:AddUserRoutes.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("UserRoutes"); int UserID = 0; String Route1 = "NULL"; String Route2 = "NULL"; String Route3 = "NULL"; String Route4 = "NULL"; String Route5 = "NULL"; try {/*ww w . j a va 2 s .c o m*/ System.out.println("Adding a new item..."); PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("UserID", UserID) .withString("Route 1", Route1).withString("Route 2", Route2).withString("Route 3", Route3) .withString("Route 4", Route4).withString("Route 5", Route5)); System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult()); } catch (Exception e) { System.err.println("Unable to add item: " + UserID); System.err.println(e.getMessage()); } }
From source file:CreateUserInfoTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserInfo"; try {// w w w.j ava2 s . co m System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:AddUserFavorites.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("UserFavorites"); int UserID = 0; String Location1 = "NULL"; String Location2 = "NULL"; String Location3 = "NULL"; String Location4 = "NULL"; String Location5 = "NULL"; try {//w w w . ja v a2s . c o m System.out.println("Adding a new item..."); PutItemOutcome outcome = table .putItem(new Item().withPrimaryKey("UserID", UserID).withString("Location 1", Location1) .withString("Location 2", Location2).withString("Location 3", Location3) .withString("Location 4", Location4).withString("Location 5", Location5)); System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult()); } catch (Exception e) { System.err.println("Unable to add item: " + UserID); System.err.println(e.getMessage()); } }
From source file:CreateUserRoutesTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserRoutes"; try {/*from w w w .j a v a2 s . c o m*/ System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:chatbot.LambdaFunctionHandler.java
License:Open Source License
@Override public String handleRequest(SlackData input, Context context) { String sResponse = ", Welcome to Service Bot"; try {// w w w. ja v a 2 s . c o m //context.getLogger().log(input); context.getLogger().log("Input Code: " + input.getCode()); context.getLogger().log("Input State: " + input.getState()); Env objEnv = input.getEnv(); String sURL = "https://slack.com/api/oauth.access"; List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("client_id", objEnv.getClientId())); urlParameters.add(new BasicNameValuePair("client_secret", objEnv.getSlackClientSecret())); urlParameters.add(new BasicNameValuePair("code", input.getCode())); urlParameters.add(new BasicNameValuePair("redirect_uri", objEnv.getSlackRedirectUrl())); String jsonInString = invokeSlackAPI(sURL, urlParameters, context); ObjectMapper mapper = new ObjectMapper(); //JSON from String to Object SlackAuth objSlackAuth = mapper.readValue(jsonInString, SlackAuth.class); sResponse = objSlackAuth.getTeam_name() + sResponse; sURL = "https://slack.com/api/channels.list"; urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token())); jsonInString = invokeSlackAPI(sURL, urlParameters, context); //JSON from String to Object SlackChannels objSlackChannels = mapper.readValue(jsonInString, SlackChannels.class); System.out.println("Channels " + objSlackChannels.getChannels()); String sSiteChannel_ID = null; String sBuyersChannel_ID = null; String sManagers_ID = null; for (Channel objChannel : objSlackChannels.getChannels()) { if (objChannel.getName().equals("site-engineers")) { sSiteChannel_ID = objChannel.getId(); } if (objChannel.getName().equals("buyers")) { sBuyersChannel_ID = objChannel.getId(); } if (objChannel.getName().equals("operations-managers")) { sManagers_ID = objChannel.getId(); } } sURL = "https://slack.com/api/channels.create"; if (sSiteChannel_ID == null) { urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token())); urlParameters.add(new BasicNameValuePair("name", "site-engineers")); jsonInString = invokeSlackAPI(sURL, urlParameters, context); ChannelAddResponse objChannelAddResponse = mapper.readValue(jsonInString, ChannelAddResponse.class); sSiteChannel_ID = (objChannelAddResponse.getChannel()).getId(); } if (sBuyersChannel_ID == null) { urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token())); urlParameters.add(new BasicNameValuePair("name", "buyers")); jsonInString = invokeSlackAPI(sURL, urlParameters, context); ChannelAddResponse objChannelAddResponse = mapper.readValue(jsonInString, ChannelAddResponse.class); sBuyersChannel_ID = (objChannelAddResponse.getChannel()).getId(); } if (sManagers_ID == null) { urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token())); urlParameters.add(new BasicNameValuePair("name", "operations-managers")); jsonInString = invokeSlackAPI(sURL, urlParameters, context); ChannelAddResponse objChannelAddResponse = mapper.readValue(jsonInString, ChannelAddResponse.class); sManagers_ID = (objChannelAddResponse.getChannel()).getId(); } AmazonDynamoDBClient objClient = new AmazonDynamoDBClient(new EnvironmentVariableCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(objClient); //Get all data set status inactive Item objNewTeam = new Item().withPrimaryKey("TEAM_ID", objSlackAuth.getTeam_id()) .withString("TEAM_NAME", objSlackAuth.getTeam_name()).withString("CHANNEL_1", sSiteChannel_ID) .withString("CHANNEL_2", sBuyersChannel_ID).withString("CHANNEL_3", sManagers_ID) .withString("ACCESS_TOKEN", objSlackAuth.getAccess_token()); Table tableCases = dynamoDB.getTable("ENTITY"); tableCases.putItem(objNewTeam); } catch (Exception e) { e.printStackTrace(); } return sResponse; }