Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,16 @@ aws --endpoint-url=http://localhost:4566 sns list-topics

```

### How to verify our Dynamo DB Table setup
```shell

aws --endpoint-url=http://localhost:4566 dynamodb list-tables

{
"TableNames": [
"test-development"
]
}

aws --endpoint-url=http://localhost:4566 dynamodb describe-table --table-name test-development > test-development.json
```
33 changes: 28 additions & 5 deletions infra/lib/ApplicationStack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as sns from '@aws-cdk/aws-sns';
import * as subs from '@aws-cdk/aws-sns-subscriptions';
import * as sqs from '@aws-cdk/aws-sqs';
import * as cdk from '@aws-cdk/core';
import * as sns from "@aws-cdk/aws-sns";
import * as subs from "@aws-cdk/aws-sns-subscriptions";
import * as sqs from "@aws-cdk/aws-sqs";
import * as cdk from "@aws-cdk/core";
import * as dynamodb from "@aws-cdk/aws-dynamodb";
import { GlobalSecondaryIndexProps, StreamViewType } from "@aws-cdk/aws-dynamodb/lib/table";
import { createStandardGSI } from "../utils/createGlobalSecondaryIndex";


export class ApplicationStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
Expand All @@ -12,7 +16,26 @@ export class ApplicationStack extends cdk.Stack {
});

const topic = new sns.Topic(this, 'SampleAppTopic');

topic.addSubscription(new subs.SqsSubscription(queue));

const table = new dynamodb.Table(this, 'Table', {
tableName: 'test-development',
// partition key & sort key
partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
sortKey: {name : 'sk', type: dynamodb.AttributeType.STRING},
// ProvisionedThroughput
readCapacity: 5,
writeCapacity: 5,
// StreamSpecification
stream: StreamViewType.NEW_AND_OLD_IMAGES,
});

const pk2Sk2Index: GlobalSecondaryIndexProps = createStandardGSI('pk2-sk2-index', 'pk2', 'sk2');
const pk3Sk3Index: GlobalSecondaryIndexProps = createStandardGSI('pk3-sk3-index', 'pk3', 'sk3');
const pk4Sk4Index: GlobalSecondaryIndexProps = createStandardGSI('pk4-sk4-index', 'pk4', 'sk4');

table.addGlobalSecondaryIndex(pk2Sk2Index);
table.addGlobalSecondaryIndex(pk3Sk3Index);
table.addGlobalSecondaryIndex(pk4Sk4Index);
}
}
Binary file modified infra/localstack/.localstack/data/dynamodb/test_us-east-1.db
Binary file not shown.
Binary file modified infra/localstack/.localstack/data/kinesis/000007.log
Binary file not shown.
11 changes: 11 additions & 0 deletions infra/localstack/.localstack/data/recorded_api_calls.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@aws-cdk/aws-sns": "1.117.0",
"@aws-cdk/aws-sns-subscriptions": "1.117.0",
"@aws-cdk/aws-sqs": "1.117.0",
"@aws-cdk/core": "1.117.0"
"@aws-cdk/core": "1.117.0",
"@aws-cdk/aws-dynamodb": "1.117.0"
}
}
117 changes: 117 additions & 0 deletions infra/setup/dynamo-table.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"AttributeDefinitions": [
{
"AttributeName": "pk",
"AttributeType": "S"
},
{
"AttributeName": "pk2",
"AttributeType": "S"
},
{
"AttributeName": "pk3",
"AttributeType": "S"
},
{
"AttributeName": "pk4",
"AttributeType": "S"
},
{
"AttributeName": "sk",
"AttributeType": "S"
},
{
"AttributeName": "sk2",
"AttributeType": "S"
},
{
"AttributeName": "sk3",
"AttributeType": "S"
},
{
"AttributeName": "sk4",
"AttributeType": "S"
}
],
"TableName": "GlobalSafetyCheck-development",
"KeySchema": [
{
"AttributeName": "pk",
"KeyType": "HASH"
},
{
"AttributeName": "sk",
"KeyType": "RANGE"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"GlobalSecondaryIndexes": [
{
"IndexName": "pk3-sk3-index",
"KeySchema": [
{
"AttributeName": "pk3",
"KeyType": "HASH"
},
{
"AttributeName": "sk3",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
}
},
{
"IndexName": "pk2-sk2-index",
"KeySchema": [
{
"AttributeName": "pk2",
"KeyType": "HASH"
},
{
"AttributeName": "sk2",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
}
},
{
"IndexName": "pk4-sk4-index",
"KeySchema": [
{
"AttributeName": "pk4",
"KeyType": "HASH"
},
{
"AttributeName": "sk4",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
}
}
],
"StreamSpecification": {
"StreamEnabled": true,
"StreamViewType": "NEW_AND_OLD_IMAGES"
}
}
141 changes: 141 additions & 0 deletions infra/setup/test-development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "pk",
"AttributeType": "S"
},
{
"AttributeName": "sk",
"AttributeType": "S"
},
{
"AttributeName": "pk2",
"AttributeType": "S"
},
{
"AttributeName": "sk2",
"AttributeType": "S"
},
{
"AttributeName": "pk3",
"AttributeType": "S"
},
{
"AttributeName": "sk3",
"AttributeType": "S"
},
{
"AttributeName": "pk4",
"AttributeType": "S"
},
{
"AttributeName": "sk4",
"AttributeType": "S"
}
],
"TableName": "test-development",
"KeySchema": [
{
"AttributeName": "pk",
"KeyType": "HASH"
},
{
"AttributeName": "sk",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2021-08-07T19:23:03.601000+07:00",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T07:00:00+07:00",
"LastDecreaseDateTime": "1970-01-01T07:00:00+07:00",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:us-east-1:000000000000:table/test-development",
"GlobalSecondaryIndexes": [
{
"IndexName": "pk3-sk3-index",
"KeySchema": [
{
"AttributeName": "pk3",
"KeyType": "HASH"
},
{
"AttributeName": "sk3",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"IndexSizeBytes": 0,
"ItemCount": 0,
"IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/test-development/index/pk3-sk3-index"
},
{
"IndexName": "pk2-sk2-index",
"KeySchema": [
{
"AttributeName": "pk2",
"KeyType": "HASH"
},
{
"AttributeName": "sk2",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"IndexSizeBytes": 0,
"ItemCount": 0,
"IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/test-development/index/pk2-sk2-index"
},
{
"IndexName": "pk4-sk4-index",
"KeySchema": [
{
"AttributeName": "pk4",
"KeyType": "HASH"
},
{
"AttributeName": "sk4",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"IndexSizeBytes": 0,
"ItemCount": 0,
"IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/test-development/index/pk4-sk4-index"
}
],
"StreamSpecification": {
"StreamEnabled": true,
"StreamViewType": "NEW_AND_OLD_IMAGES"
},
"LatestStreamLabel": "2021-08-07T12:23:03.601",
"LatestStreamArn": "arn:aws:dynamodb:us-east-1:000000000000:table/test-development/stream/2021-08-07T12:23:03.601"
}
}
18 changes: 18 additions & 0 deletions infra/utils/createGlobalSecondaryIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AttributeType, ProjectionType, GlobalSecondaryIndexProps } from "@aws-cdk/aws-dynamodb";

/**
* Default pk & sk is attr type is STRING & read/write capacity is 5.
* @param indexName
* @param pkName
* @param skName
*/
export const createStandardGSI = (indexName: string, pkName: string, skName: string) : GlobalSecondaryIndexProps => {
return {
indexName,
partitionKey: { name: pkName, type: AttributeType.STRING },
sortKey: { name: skName, type: AttributeType.STRING },
projectionType: ProjectionType.ALL,
readCapacity: 5,
writeCapacity: 5,
};
}
Loading