当前位置: 首页>>代码示例>>Java>>正文


Java AmazonDynamoDB类代码示例

本文整理汇总了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;
}
 
开发者ID:Erudika,项目名称:para,代码行数:34,代码来源:AWSDynamoUtils.java

示例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;
}
 
开发者ID:arun-gupta,项目名称:alexa-skill-java,代码行数:19,代码来源:DBUtil.java

示例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;
}
 
开发者ID:arun-gupta,项目名称:tweet-analysis,代码行数:21,代码来源:DynamoDBUtil.java

示例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;
}
 
开发者ID:arun-gupta,项目名称:dynamodb-java-helloworld,代码行数:18,代码来源:App.java

示例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;
}
 
开发者ID:dehora,项目名称:outland,代码行数:20,代码来源:DefaultGroupStorage.java

示例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();
    }
 
开发者ID:satr,项目名称:aws-amazon-shopping-bot-lambda-func,代码行数:20,代码来源:TestRepositoryHelper.java

示例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();
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:17,代码来源:GenericDynamoDB.java

示例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);
}
 
开发者ID:jessecoyle,项目名称:jcredstash,代码行数:17,代码来源:JCredStashTest.java

示例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();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:24,代码来源:LambdaLock.java

示例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);
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:25,代码来源:AmazonDynamoDBFactoryTest.java

示例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());
	}
}
 
开发者ID:janloeffler,项目名称:aws-utilization-monitor,代码行数:34,代码来源:AwsScan.java

示例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);
}
 
开发者ID:qubole,项目名称:presto-kinesis,代码行数:18,代码来源:KinesisShardCheckpointer.java

示例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);
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:23,代码来源:DynamoDbTemplateTest.java

示例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;
		}
	}
}
 
开发者ID:awslabs,项目名称:amazon-kinesis-aggregators,代码行数:35,代码来源:DynamoUtils.java

示例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;
			}
		}
	}
}
 
开发者ID:awslabs,项目名称:amazon-kinesis-aggregators,代码行数:34,代码来源:DynamoUtils.java


注:本文中的com.amazonaws.services.dynamodbv2.AmazonDynamoDB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。