Last active
April 24, 2017 04:14
-
-
Save gabanox/1df6088fbcf7232d32e712521ed6e0a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hipermediasoft.manager; | |
import com.amazonaws.ClientConfiguration; | |
import com.amazonaws.auth.AWSCredentialsProvider; | |
import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider; | |
import com.amazonaws.regions.Regions; | |
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; | |
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; | |
public class DynamoDBManager { | |
private DynamoDBMapper mapper; | |
private static volatile DynamoDBManager instance; | |
public static final String DYNAMODB_ENDPOINT = System.getenv("DYNAMODB_ENDPOINT"); | |
public DynamoDBManager(){ | |
ClientConfiguration clientConfiguration = new ClientConfiguration() | |
.withMaxErrorRetry(5); | |
AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfiguration); | |
client.configureRegion(Regions.fromName(System.getenv("REGION"))); | |
client.withEndpoint(DynamoDBManager.DYNAMODB_ENDPOINT); | |
//Usar solo en caso de que necesiten asociar algun item a una URL de S3 con la clase helper S3Link | |
AWSCredentialsProvider s3CredentialProvider = new ClasspathPropertiesFileCredentialsProvider(); | |
mapper = new DynamoDBMapper(client, s3CredentialProvider); | |
} | |
public static DynamoDBManager instance(){ | |
if (instance == null) { | |
synchronized(DynamoDBManager.class) { | |
if (instance == null) | |
instance = new DynamoDBManager(); | |
} | |
} | |
return instance; | |
} | |
public static DynamoDBMapper mapper() { | |
DynamoDBManager manager = instance(); | |
return manager.mapper; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment