Java Code Examples for com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient#setRegion()

The following examples show how to use com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient#setRegion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utilities.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
public synchronized GeoDataManager setupGeoDataManager() {
	if (geoDataManager == null) {
		String accessKey = getSystemProperty( "AWS_ACCESS_KEY_ID" ); 
		String secretKey = getSystemProperty( "AWS_SECRET_KEY" );
		String regionName = getSystemProperty( "PARAM2", "us-east-1" ); 
		String tableName = getSystemProperty( "PARAM3", "PhotoLocations" );

		AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
		AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials);
		Region region = Region.getRegion(Regions.fromName(regionName));
		ddb.setRegion(region);

		GeoDataManagerConfiguration config = new GeoDataManagerConfiguration(ddb, tableName);
		geoDataManager = new GeoDataManager(config);
	}

	return geoDataManager;
}
 
Example 2
Source File: Utilities.java    From dynamodb-geo with Apache License 2.0 6 votes vote down vote up
private synchronized void setupGeoDataManager() {
	if (geoDataManager == null) {
		String accessKey = System.getProperty("AWS_ACCESS_KEY_ID");
		String secretKey = System.getProperty("AWS_SECRET_KEY");
		String tableName = System.getProperty("PARAM1");
		String regionName = System.getProperty("PARAM2");

		Region region = Region.getRegion(Regions.fromName(regionName));
		ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20);
		AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

		AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials, clientConfiguration);
		ddb.setRegion(region);

		GeoDataManagerConfiguration config = new GeoDataManagerConfiguration(ddb, tableName);
		geoDataManager = new GeoDataManager(config);
	}
}
 
Example 3
Source File: UserAuthentication.java    From amazon-cognito-developer-authentication-sample with Apache License 2.0 5 votes vote down vote up
/**
 * Looks up table name and creates one if it does not exist
 */
public UserAuthentication() {
    ddb = new AmazonDynamoDBClient();
    ddb.setRegion(RegionUtils.getRegion(Configuration.REGION));

    try {
        if (!doesTableExist(USER_TABLE)) {
            createIdentityTable();
        }
    } catch (DataAccessException e) {
        throw new RuntimeException("Failed to create device table.", e);
    }
}
 
Example 4
Source File: DeviceAuthentication.java    From amazon-cognito-developer-authentication-sample with Apache License 2.0 5 votes vote down vote up
/**
 * Looks up table name and creates one if it does not exist
 */
public DeviceAuthentication() {
    ddb = new AmazonDynamoDBClient();
    ddb.setRegion(RegionUtils.getRegion(Configuration.REGION));
    
    try {
        if (!doesTableExist(DEVICE_TABLE)) {
            createDeviceTable();
        }
    } catch (DataAccessException e) {
        throw new RuntimeException("Failed to create device table.", e);
    }
}
 
Example 5
Source File: DynamoDBBackendImpl.java    From fiware-cygnus with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Constructor.
 * @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);
}
 
Example 6
Source File: GeoDynamoDBServlet.java    From dynamodb-geo with Apache License 2.0 5 votes vote down vote up
private void setupGeoDataManager() {
	String accessKey = System.getProperty("AWS_ACCESS_KEY_ID");
	String secretKey = System.getProperty("AWS_SECRET_KEY");
	String tableName = System.getProperty("PARAM1");
	String regionName = System.getProperty("PARAM2");

	AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
	AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials);
	Region region = Region.getRegion(Regions.fromName(regionName));
	ddb.setRegion(region);

	config = new GeoDataManagerConfiguration(ddb, tableName);
	geoDataManager = new GeoDataManager(config);
}
 
Example 7
Source File: ITAbstractDynamoDBTest.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
    FileInputStream fis = new FileInputStream(CREDENTIALS_FILE);
    final PropertiesCredentials credentials = new PropertiesCredentials(fis);
    amazonDynamoDBClient = new AmazonDynamoDBClient(credentials);
    dynamoDB = new DynamoDB(amazonDynamoDBClient);
    amazonDynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2));

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("hashS").withAttributeType("S"));
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("rangeS").withAttributeType("S"));

    ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashS").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeS").withKeyType(KeyType.RANGE));

    CreateTableRequest request = new CreateTableRequest()
        .withTableName(stringHashStringRangeTableName)
        .withKeySchema(keySchema)
        .withAttributeDefinitions(attributeDefinitions)
        .withProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(5L)
            .withWriteCapacityUnits(6L));
    Table stringHashStringRangeTable = dynamoDB.createTable(request);
    stringHashStringRangeTable.waitForActive();

    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("rangeN").withAttributeType("N"));

    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeN").withKeyType(KeyType.RANGE));

    request = new CreateTableRequest()
        .withTableName(numberHashNumberRangeTableName)
        .withKeySchema(keySchema)
        .withAttributeDefinitions(attributeDefinitions)
        .withProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(5L)
            .withWriteCapacityUnits(6L));
    Table numberHashNumberRangeTable = dynamoDB.createTable(request);
    numberHashNumberRangeTable.waitForActive();

    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));

    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));

    request = new CreateTableRequest()
        .withTableName(numberHashOnlyTableName)
        .withKeySchema(keySchema)
        .withAttributeDefinitions(attributeDefinitions)
        .withProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(5L)
            .withWriteCapacityUnits(6L));
    Table numberHashOnlyTable = dynamoDB.createTable(request);
    numberHashOnlyTable.waitForActive();

}
 
Example 8
Source File: DynamoDBManager.java    From lambda-java8-dynamodb with Apache License 2.0 4 votes vote down vote up
private DynamoDBManager() {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setRegion(Region.getRegion(Regions.US_EAST_1));
        mapper = new DynamoDBMapper(client);
    }
 
Example 9
Source File: ITAbstractDynamoDBTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
    FileInputStream fis = new FileInputStream(CREDENTIALS_FILE);
    final PropertiesCredentials credentials = new PropertiesCredentials(fis);
    amazonDynamoDBClient = new AmazonDynamoDBClient(credentials);
    dynamoDB = new DynamoDB(amazonDynamoDBClient);
    amazonDynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2));

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("hashS").withAttributeType("S"));
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("rangeS").withAttributeType("S"));

    ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashS").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeS").withKeyType(KeyType.RANGE));

    CreateTableRequest request = new CreateTableRequest()
        .withTableName(stringHashStringRangeTableName)
        .withKeySchema(keySchema)
        .withAttributeDefinitions(attributeDefinitions)
        .withProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(5L)
            .withWriteCapacityUnits(6L));
    Table stringHashStringRangeTable = dynamoDB.createTable(request);
    stringHashStringRangeTable.waitForActive();

    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("rangeN").withAttributeType("N"));

    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeN").withKeyType(KeyType.RANGE));

    request = new CreateTableRequest()
        .withTableName(numberHashNumberRangeTableName)
        .withKeySchema(keySchema)
        .withAttributeDefinitions(attributeDefinitions)
        .withProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(5L)
            .withWriteCapacityUnits(6L));
    Table numberHashNumberRangeTable = dynamoDB.createTable(request);
    numberHashNumberRangeTable.waitForActive();

    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
        .add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));

    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));

    request = new CreateTableRequest()
        .withTableName(numberHashOnlyTableName)
        .withKeySchema(keySchema)
        .withAttributeDefinitions(attributeDefinitions)
        .withProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(5L)
            .withWriteCapacityUnits(6L));
    Table numberHashOnlyTable = dynamoDB.createTable(request);
    numberHashOnlyTable.waitForActive();

}
 
Example 10
Source File: SavePersonHandler.java    From tutorials with MIT License 4 votes vote down vote up
private void initDynamoDbClient() {
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    client.setRegion(Region.getRegion(REGION));
    this.dynamoDb = new DynamoDB(client);
}