Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
amazon_dynamodb [2018/04/04 13:29]
root [Streams]
amazon_dynamodb [2018/06/11 05:48] (current)
root [Streams]
Line 12: Line 12:
 ** The first attribute is the partition key ** The first attribute is the partition key
 ** second attribute is the sort key.  ** second attribute is the sort key. 
 +
 +== AWS CLI == 
 +Describe a table 
 +
 +<​code> ​
 +aws dynamodb describe-table --table-name prod-catalog-v2 --region eu-west-1
 +</​code>​
 +
 +and scan 
 +
 +<​code>​
 +aws dynamodb scan --table-name prod-catalog-v2 --region eu-west-1
 +</​code>​
 +
 +
 +
  
  
Line 97: Line 113:
 Note also the  https://​github.com/​awslabs/​dynamodb-streams-kinesis-adapter which says Note also the  https://​github.com/​awslabs/​dynamodb-streams-kinesis-adapter which says
 "Using the Kinesis Adapter is the recommended way to consume Streams from DynamoDB."​ "Using the Kinesis Adapter is the recommended way to consume Streams from DynamoDB."​
 +
 +An example of a kinesis stream listener https://​docs.aws.amazon.com/​amazondynamodb/​latest/​developerguide/​Streams.KCLAdapter.Walkthrough.CompleteProgram.html
 == Links and Reference == == Links and Reference ==
  
Line 109: Line 127:
 java -Djava.library.path=./​DynamoDBLocal_lib -jar DynamoDBLocal.jar --port 8001 java -Djava.library.path=./​DynamoDBLocal_lib -jar DynamoDBLocal.jar --port 8001
 </​code>​ </​code>​
 +
 +=== Running and Embedded Dynamodb === 
 +
 +<code java>
 +  FileUtils.copyFile(new File("​libs/​libsqlite4java-linux-amd64.so"​),​ new File(System.getProperty("​java.io.tmpdir"​) + "/​libsqlite4java-linux-amd64.so"​));​
 +        System.load(System.getProperty("​java.io.tmpdir"​) + "/​libsqlite4java-linux-amd64.so"​);​
 +
 +        // now create client and table
 +        AmazonDynamoDBLocal amazonDynamoDBLocal = DynamoDBEmbedded.create();​
 +
 +        dbLocal = amazonDynamoDBLocal.amazonDynamoDB();​
 +        db = new DynamoDB(dbLocal);​
 +        CreateTableResult result = dbLocal.createTable(new CreateTableRequest().withTableName("​catalog-v2"​)
 +                .withKeySchema(new KeySchemaElement().withAttributeName("​id"​).withKeyType(KeyType.HASH))
 +                .withAttributeDefinitions(new AttributeDefinition().withAttributeName("​id"​).withAttributeType(ScalarAttributeType.S))
 +                .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L))
 +        );
 +
 +        Table table = db.getTable("​catalog-v2"​);​
 +        File test = new File("​test"​);​
 +                System.err.println("​local path " + test.getAbsolutePath());​
 +        Resource resouce = resourceLoader.getResource("​classpath:​testData/​catalog-v2.json"​);​
 +
 +
 +
 +        String data = FileUtils.readFileToString( resouce.getFile());​
 +        JSONObject jsonData = new JSONObject(data);​
 +
 +        // put json direct
 +        table.putItem(Item.fromJSON(data));​
 +        Item item = table.getItem(new PrimaryKey("​id",​ "​516037-289558-289559"​));​
 +</​code> ​       ​
 +
 +== Testing with Spring == 
 +
 +<code java>
 +@RunWith(SpringJUnit4ClassRunner.class)
 +@SpringBootTest(classes = Application.class)
 +@WebAppConfiguration
 +@ActiveProfiles("​local"​)
 +@TestPropertySource(properties = { 
 +  "​amazon.dynamodb.endpoint=http://​localhost:​8000/", ​
 +  "​amazon.aws.accesskey=test1", ​
 +  "​amazon.aws.secretkey=test231"​ })
 +public class ProductInfoRepositoryIntegrationTest {
 + 
 +    private DynamoDBMapper dynamoDBMapper;​
 + 
 +    @Autowired
 +    private AmazonDynamoDB amazonDynamoDB;​
 +</​code> ​
 
amazon_dynamodb.1522873765.txt.gz · Last modified: 2018/04/04 13:29 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd