本文整理汇总了Java中com.amazonaws.services.dynamodbv2.AmazonDynamoDB类的典型用法代码示例。如果您正苦于以下问题:Java AmazonDynamoDB类的具体用法?Java AmazonDynamoDB怎么用?Java AmazonDynamoDB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonDynamoDB类属于com.amazonaws.services.dynamodbv2包,在下文中一共展示了AmazonDynamoDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClient
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
/**
* Returns a client instance for AWS DynamoDB.
* @return a client that talks to DynamoDB
*/
public static AmazonDynamoDB getClient() {
if (ddbClient != null) {
return ddbClient;
}
if (Config.IN_PRODUCTION) {
ddbClient = AmazonDynamoDBClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(Config.AWS_ACCESSKEY, Config.AWS_SECRETKEY))).
withRegion(Config.AWS_REGION).build();
} else {
ddbClient = AmazonDynamoDBClientBuilder.standard().
withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("local", "null"))).
withEndpointConfiguration(new EndpointConfiguration(LOCAL_ENDPOINT, "")).build();
}
if (!existsTable(Config.getRootAppIdentifier())) {
createTable(Config.getRootAppIdentifier());
}
ddb = new DynamoDB(ddbClient);
Para.addDestroyListener(new DestroyListener() {
public void onDestroy() {
shutdownClient();
}
});
return ddbClient;
}
示例2: getClient
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
private static AmazonDynamoDB getClient() {
if (null != dynamodbClient) {
return dynamodbClient;
}
String region = System.getProperty("DYNAMODB_REGION");
if (null == region) {
System.err.println("Region not set, default \"" + Regions.US_EAST_1.name() + "\" is used");
region = Regions.US_EAST_1.name();
}
System.out.println("DynamoDB region: " + region);
dynamodbClient = AmazonDynamoDBClientBuilder.standard()
.withRegion(region)
.build();
return dynamodbClient;
}
示例3: getClient
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
public static final AmazonDynamoDB getClient() {
if (null != dynamodbClient) {
return dynamodbClient;
}
String region = System.getenv("DYNAMODB_REGION");
if (null == region) {
System.err.println("Region is null, using default \"" + Regions.US_WEST_1 + "\"");
region = Regions.US_WEST_1.name();
}
System.out.println("DynamoDB region: " + region);
dynamodbClient = AmazonDynamoDBClientBuilder.standard()
.withRegion(region)
.build();
System.out.println("Got DynamoDB client...");
return dynamodbClient;
}
示例4: getClient
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
private static AmazonDynamoDB getClient() {
if (null != dynamodbClient)
return dynamodbClient;
String region = System.getProperty("DYNAMODB_REGION");
if (null == region) {
System.err.println("Region not set, default \"" + Regions.US_WEST_1.name() + "\" is used");
region = Regions.US_WEST_1.name();
}
System.out.println("DynamoDB region: " + region);
dynamodbClient = AmazonDynamoDBClientBuilder.standard()
.withRegion(region)
.build();
return dynamodbClient;
}
示例5: DefaultGroupStorage
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
@Inject
public DefaultGroupStorage(
AmazonDynamoDB amazonDynamoDB,
TableConfiguration tableConfiguration,
@Named("dynamodbGroupWriteHystrix") HystrixConfiguration dynamodbGroupWriteHystrix,
@Named("dynamodbGraphWriteHystrix") HystrixConfiguration dynamodbGraphWriteHystrix,
@Named("dynamodbNamespaceGraphQueryHystrix")
HystrixConfiguration dynamodbNamespaceGraphQueryHystrix,
MetricRegistry metrics
) {
this.amazonDynamoDB = amazonDynamoDB;
this.dynamoDB = new DynamoDB(this.amazonDynamoDB);
this.groupTableName = tableConfiguration.outlandGroupsTable;
this.groupGraphTableName = tableConfiguration.outlandAppGraphTable;
this.dynamodbGroupWriteHystrix = dynamodbGroupWriteHystrix;
this.dynamodbGraphWriteHystrix = dynamodbGraphWriteHystrix;
this.dynamodbNamespaceGraphQueryHystrix = dynamodbNamespaceGraphQueryHystrix;
this.metrics = metrics;
}
示例6: createTable
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
private static void createTable(AmazonDynamoDB dynamodb, String tableName, String tableKeyFieldName) {
List<AttributeDefinition> attributeDefinitions= new ArrayList<>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName(tableKeyFieldName).withAttributeType("S"));
List<KeySchemaElement> keySchema = new ArrayList<>();
keySchema.add(new KeySchemaElement().withAttributeName(tableKeyFieldName).withKeyType(KeyType.HASH));
CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(keySchema)
.withAttributeDefinitions(attributeDefinitions)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(1L)
.withWriteCapacityUnits(1L));
dynamodb.createTable(request);
//TODO: just to look at the result, if needed
// TableDescription table = dynamodb.describeTable(tableName).getTable();
}
示例7: GenericDynamoDB
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
public GenericDynamoDB(AmazonDynamoDB client, AWSCredentialsProvider awsCredentials,
ClientConfiguration clientConfiguration,
SecretsGroupIdentifier groupIdentifier, Class<Entry> clazz, Converters converters,
ReadWriteLock readWriteLock) {
this.clazz = clazz;
buildMappings();
this.converters = converters;
this.awsCredentials = awsCredentials;
this.clientConfiguration = clientConfiguration;
this.client = client;
this.region = RegionUtils.getRegion(groupIdentifier.region.getName());
this.readWriteLock = readWriteLock;
RegionLocalResourceName resourceName = new RegionLocalResourceName(groupIdentifier);
this.tableName = resourceName.toString();
}
示例8: setUp
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
@Before
public void setUp() {
dynamoDBClient = Mockito.mock(AmazonDynamoDB.class);
GenerateDataKeyResult generateDatakeyResult = new GenerateDataKeyResult();
generateDatakeyResult.setCiphertextBlob(Mockito.mock(ByteBuffer.class));
generateDatakeyResult.setPlaintext(Mockito.mock(ByteBuffer.class));
DecryptResult decryptResult = new DecryptResult();
decryptResult.setKeyId("alias/foo");
decryptResult.setPlaintext(Mockito.mock(ByteBuffer.class));
awskmsClient = Mockito.mock(AWSKMS.class);
Mockito.when(awskmsClient.generateDataKey(Mockito.any(GenerateDataKeyRequest.class))).thenReturn(generateDatakeyResult);
Mockito.when(awskmsClient.decrypt(Mockito.any(DecryptRequest.class))).thenReturn(decryptResult);
}
示例9: createItemIfNotExists
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
boolean createItemIfNotExists(String key, long currentTimeMillis, Context context) {
LambdaLogger logger = context.getLogger();
AmazonDynamoDB client = createDynamoDBClient(cc);
String functionName = context.getFunctionName();
try {
// Create a record if it does not exist
PutItemRequest req = new PutItemRequest().withTableName(TABLE_NAME)
.addItemEntry(COL_FUNCTION_NAME, new AttributeValue(functionName))
.addItemEntry(COL_KEY, new AttributeValue(key))
.addItemEntry(COL_CREATED_TIME, new AttributeValue().withN(Long.toString(currentTimeMillis)))
.addExpectedEntry(COL_FUNCTION_NAME, new ExpectedAttributeValue().withExists(false))
.addExpectedEntry(COL_KEY, new ExpectedAttributeValue().withExists(false));
client.putItem(req);
return true;
} catch (ConditionalCheckFailedException e) {
logger.log("Record exsited. functionName[" + functionName + "] key[" + key + "]");
return false;
} finally {
client.shutdown();
}
}
示例10: testProvide
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
@Test
public void testProvide() {
Env env = new Env().register("DYNAMODB_ENDPOINT", "fakeendpoint");
ClientConfiguration config = new ClientConfiguration();
config.setRetryPolicy(PredefinedRetryPolicies.NO_RETRY_POLICY);
AWSCredentialsProvider credentialsProvider = new StaticCredentialsProvider(
new BasicAWSCredentials("fake_access_key_id", "fake_secret_access_key"));
AmazonDynamoDBFactory factory = new AmazonDynamoDBFactory(env, credentialsProvider, config);
AmazonDynamoDB dynamoDB = factory.provide();
String message = "";
try {
dynamoDB.listTables();
} catch (AmazonClientException e) {
message = e.getMessage();
}
assertTrue(message.startsWith("Unable to execute HTTP request: fakeendpoint"));
factory.dispose(dynamoDB);
}
示例11: scanDynamoDB
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
/**
* Collect data for DynamoDB.
*
* @param stats
* current statistics object.
* @param account
* currently used credentials object.
* @param region
* currently used aws region.
*/
public static void scanDynamoDB(AwsStats stats, AwsAccount account, Regions region) {
LOG.debug("Scan for DynamoDB in region " + region.getName() + " in account " + account.getAccountId());
/*
* Amazon DynamoDB
*/
try {
AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(account.getCredentials());
dynamoDB.setRegion(Region.getRegion(region));
List<String> list = dynamoDB.listTables().getTableNames();
int totalItems = list.size();
for (String tableName : list) {
AwsResource res = new AwsResource(tableName, account.getAccountId(), AwsResourceType.DynamoDB, region);
stats.add(res);
}
LOG.info(totalItems + " DynamoDB tables in region " + region.getName() + " in account " + account.getAccountId());
} catch (AmazonServiceException ase) {
LOG.error("Exception of DynamoDB: " + ase.getMessage());
}
}
示例12: KinesisShardCheckpointer
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
public KinesisShardCheckpointer(AmazonDynamoDB dynamoDBClient,
String dynamoDBTable,
KinesisSplit kinesisSplit,
String logicalProcessName,
int curIterationNumber,
long checkpointIntervalMS,
long dynamoReadCapacity,
long dynamoWriteCapacity)
{
this(new KinesisClientLeaseManager(dynamoDBTable, dynamoDBClient),
kinesisSplit,
logicalProcessName,
curIterationNumber,
checkpointIntervalMS,
dynamoReadCapacity,
dynamoWriteCapacity);
}
示例13: shouldNotGenerateKeys_withNoSequenceConfigurations
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
@Test
public void shouldNotGenerateKeys_withNoSequenceConfigurations() throws Exception {
// Given
final String sequenceName = randomString(10);
final Collection<SequenceConfiguration> sequenceConfigurations = new ArrayList<>();
when(mockDatabaseSchemaHolder.sequenceConfigurations()).thenReturn(sequenceConfigurations);
final AmazonDynamoDB mockAmazonDynamoDbClient = mock(AmazonDynamoDB.class);
final SequenceKeyGenerator sequenceKeyGenerator = new SequenceKeyGenerator(sequenceName);
final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(mockDatabaseSchemaHolder);
dynamoDbTemplate.initialize(mockAmazonDynamoDbClient);
// When
IllegalStateException actualException = null;
try {
dynamoDbTemplate.generateKeys(sequenceKeyGenerator);
} catch (final IllegalStateException e) {
actualException = e;
}
// Then
assertNotNull(actualException);
}
示例14: safeCreateTable
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
/**
* Private interface for creating tables which handles any instances of
* Throttling of the API
*
* @param dynamoClient
* @param dynamoTable
* @return
* @throws Exception
*/
public static CreateTableResult safeCreateTable(
final AmazonDynamoDB dynamoClient,
final CreateTableRequest createTableRequest) throws Exception {
CreateTableResult res = null;
final int tryMax = 10;
int tries = 0;
while (true) {
try {
res = dynamoClient.createTable(createTableRequest);
return res;
} catch (LimitExceededException le) {
if (tries < tryMax) {
// back off for 1 second
Thread.sleep(1000);
tries++;
} else {
throw le;
}
} catch (ResourceInUseException rie) {
// someone else is trying to create the table while we are, so
// return ok
return null;
}
}
}
示例15: safeDescribeTable
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入依赖的package包/类
/**
* Private interface for describing tables which handles any instances of
* Throttling of the API
*
* @param dynamoClient
* @param dynamoTable
* @return
* @throws Exception
*/
public static DescribeTableResult safeDescribeTable(
final AmazonDynamoDB dynamoClient, final String dynamoTable)
throws Exception {
DescribeTableResult res = null;
final int tryMax = 10;
int tries = 0;
while (true) {
try {
res = dynamoClient.describeTable(dynamoTable);
return res;
} catch (ResourceNotFoundException e) {
if (tries < tryMax) {
// sleep for a short time as this is potentially an eventual
// consistency issue with the table having been created ms
// ago
Thread.sleep(10);
tries++;
} else {
throw e;
}
}
}
}