List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient setRegion
@Deprecated public void setRegion(Region region) throws IllegalArgumentException
From source file:awslabs.lab22.Lab22.java
License:Open Source License
/** * Controls the flow of the lab code execution. *//* w w w. j a va2 s . c o m*/ public static void main(String[] args) { try { // Create DynamoDB client and set the region to US East (Virginia) AmazonDynamoDBClient ddbClient = new AmazonDynamoDBClient( new ClasspathPropertiesFileCredentialsProvider()); ddbClient.setRegion(region); List<Account> accounts = new ArrayList<Account>(); accounts.add(new Account().withCompany("Amazon.com").withEmail("johndoe@amazon.com").withFirst("John") .withLast("Doe").withAge("33")); accounts.add(new Account().withCompany("Asperatus Tech").withEmail("janedoe@amazon.com") .withFirst("Jane").withLast("Doe").withAge("24")); accounts.add(new Account().withCompany("Amazon.com").withEmail("jimjohnson@amazon.com").withFirst("Jim") .withLast("Johnson")); // Verify that the table schema is as we expect, and correct any // problems we find. if (!confirmTableSchema(ddbClient, tableName)) { System.out.print("Deleting. "); optionalLabCode.deleteTable(ddbClient, tableName); System.out.print("Rebuilding. "); optionalLabCode.buildTable(ddbClient, tableName); System.out.println("Done."); } System.out.println("Adding items to table."); // Create the accounts for (Account account : accounts) { labCode.createAccountItem(ddbClient, tableName, account); System.out.println("Added item: " + account.getCompany() + "/" + account.getEmail()); } System.out.println("Requesting matches for Company == Amazon.com"); QueryResult queryResult = labCode.lookupByHashKey(ddbClient, tableName, "Amazon.com"); if (queryResult != null && queryResult.getCount() > 0) { // Record was found for (Map<String, AttributeValue> item : queryResult.getItems()) { System.out.println("Item Found-"); for (Entry<String, AttributeValue> attribute : item.entrySet()) { System.out.print(" " + attribute.getKey() + ":"); if (attribute.getKey().equals("Age")) { System.out.println(attribute.getValue().getN()); } else { System.out.println(attribute.getValue().getS()); } } } } else { System.out.println("No matches found."); } // Conditionally update a record System.out.print("Attempting update. "); labCode.updateIfMatch(ddbClient, tableName, "jimjohnson@amazon.com", "Amazon.com", "James", "Jim"); System.out.println("Done."); } catch (Exception ex) { LabUtility.dumpError(ex); } }
From source file:awslabs.lab22.StudentCode.java
License:Open Source License
/** * Create a DynamoDB item from the values specified in the account parameter. The names of the attributes in the * item should match the corresponding property names in the Account object. Don't add attributes for fields in the * Account object that are empty./*from ww w .j ava 2s. co m*/ * * Since the Company and Email attributes are part of the table key, those will always be provided in the Account * object when this method is called. This method will be called multiple times by the code controlling the lab. * * Important: Even thought the Account.Age property is passed to you as a string, add it to the item as a numerical * value. * * @param ddbClient The DynamoDB client object. * @param tableName The name of the table to add the item to. * @param account The Account object containing the data to add. */ @Override public void createAccountItem(AmazonDynamoDBClient ddbClient, String tableName, Account account) { // TODO: Replace this call to the super class with your own implementation of the method. ddbClient.setRegion(Region.getRegion(Regions.US_EAST_1)); Map<String, AttributeValue> items = new HashMap<String, AttributeValue>(); items.put("Company", new AttributeValue().withS(account.getCompany())); items.put("Email", new AttributeValue().withS(account.getEmail())); if (account.getFirst() != null) { items.put("First", new AttributeValue().withS(account.getFirst())); } if (account.getLast() != null) { items.put("Last", new AttributeValue().withS(account.getLast())); } if (account.getAge() != null) { items.put("Age", new AttributeValue().withN(account.getAge())); } PutItemRequest request = new PutItemRequest().withTableName(tableName).withItem(items); ddbClient.putItem(request); }
From source file:awslabs.lab51.SolutionCode.java
License:Open Source License
@Override public AmazonDynamoDBClient createDynamoDbClient(AWSCredentials credentials) { Region region = Region.getRegion(Regions.fromName(System.getProperty("REGION"))); AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setRegion(region); return client; }
From source file:com.innoq.hagmans.bachelor.TemperatureConsumer.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { if (args.length == 2) { streamName = args[0];//w w w. j a v a2 s.com db_name = args[1]; } // Initialize Utils KinesisClientLibConfiguration config = new KinesisClientLibConfiguration(db_name, streamName, new DefaultAWSCredentialsProviderChain(), "KinesisProducerLibSampleConsumer") .withRegionName(TemperatureProducer.REGION) .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON); Region region = RegionUtils.getRegion(TemperatureProducer.REGION); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient(credentialsProvider, new ClientConfiguration()); AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentialsProvider); client.setRegion(region); DynamoDB dynamoDB = new DynamoDB(client); amazonDynamoDB.setRegion(region); DynamoDBUtils dbUtils = new DynamoDBUtils(dynamoDB, amazonDynamoDB, client); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, new ClientConfiguration()); kinesis.setRegion(region); StreamUtils streamUtils = new StreamUtils(kinesis); try { if (!streamUtils.isActive(kinesis.describeStream(streamName))) { log.info("Stream is not active. Waiting for Stream to become active...."); streamUtils.waitForStreamToBecomeActive(streamName); } } catch (ResourceNotFoundException e) { log.info("Stream is not created right now. Waiting for stream to get created and become active...."); streamUtils.waitForStreamToBecomeActive(streamName); } dbUtils.deleteTable(db_name); dbUtils.createTemperatureTableIfNotExists(tableName); Thread.sleep(1000); final TemperatureConsumer consumer = new TemperatureConsumer(); new Worker.Builder().recordProcessorFactory(consumer).config(config).build().run(); }
From source file:com.kitac.kinesissamples.consumer.communication.DynamoDBManager.java
License:Open Source License
private DynamoDBManager() { config = new ClientConfiguration(); /* TODO: ClientConfiguration setting code is here. */ AmazonDynamoDBClient client = new AmazonDynamoDBClient( // For use IAM role, specify DefaultAWSCredentialsProviderChain instance. new DefaultAWSCredentialsProviderChain(), config); client.setRegion(Regions.AP_NORTHEAST_1); dynamoDBConnection = new DynamoDB(client); }
From source file:com.optimalbi.AmazonAccount.java
License:Apache License
private void populateDynamoDB() throws AmazonClientException { getRegions().stream().filter(region -> region.isServiceSupported(ServiceAbbreviations.Dynamodb)) .forEach(region -> {/*from w w w . j ava 2 s .c o m*/ AmazonDynamoDBClient DDB = new AmazonDynamoDBClient(credentials.getCredentials()); DDB.setRegion(region); DynamoDB dynamoDB = new DynamoDB(DDB); TableCollection<ListTablesResult> tables = dynamoDB.listTables(); tables.forEach(table -> services.add(new LocalDynamoDBService(table.getTableName(), credentials, region, table.describe(), logger))); }); }
From source file:com.serverless.manager.DynamoDBManager.java
License:Open Source License
private DynamoDBManager() { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setRegion(Region.getRegion(Regions.US_WEST_1)); mapper = new DynamoDBMapper(client); }
From source file:com.telefonica.iot.cygnus.backends.dynamo.DynamoDBBackendImpl.java
License:Open Source License
/** * Constructor.//from w ww . j a v a 2s . com * @param accessKeyId * @param secretAccessKey * @param region */ public DynamoDBBackendImpl(String accessKeyId, String secretAccessKey, String region) { BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, secretAccessKey); AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsCredentials); client.setRegion(Region.getRegion(Regions.fromName(region))); dynamoDB = new DynamoDB(client); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.services.GeoPosicionamientoPublicacionesService.java
private void setupGeoDataManager() { String tableName = "Posicion"; String regionName = "us-west-2"; Region region = Region.getRegion(Regions.fromName(regionName)); ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration); ddb.setRegion(region); config = new GeoDataManagerConfiguration(ddb, tableName); geoDataManager = new GeoDataManager(config); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.services.GeoPosicionamientoUsuariosService.java
private void setupGeoDataManager() { String tableName = "PosicionUsuarios"; String regionName = "us-west-2"; Region region = Region.getRegion(Regions.fromName(regionName)); ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration); ddb.setRegion(region); config = new GeoDataManagerConfiguration(ddb, tableName); geoDataManager = new GeoDataManager(config); }