public DynamoStack()

in src/main/java/com/awsblog/queueing/cdk/DynamoStack.java [52:133]


	public DynamoStack(final Construct parent, final String id,
							Configuration config, final StackProps props, Map<String, IRole> roles) {

		super(parent, id, props);

		Table table = null;

		int count = 0;

		for(ConfigTable tableMeta : config.getTables()) {

			System.out.printf("[%d] CDK .. table processing: [%s]%n", ++count, tableMeta.getTableName());

			//String logicalTableName = tableMeta.getLogicalName();

			AttributeType pkType = AttributeType.STRING;
			if (tableMeta.getPartitionKey().getAttributeType().toLowerCase().startsWith("num")) pkType = AttributeType.NUMBER;
			else if (tableMeta.getPartitionKey().getAttributeType().toLowerCase().startsWith("bin")) pkType = AttributeType.BINARY;

			TableProps.Builder tableBuilder = TableProps.builder()
					.tableName(tableMeta.getTableName())
					//.withBillingMode(BillingMode.PAY_PER_REQUEST)
					.serverSideEncryption(true)
					.partitionKey(Attribute.builder()
							.name(tableMeta.getPartitionKey().getAttributeName())
							.type(pkType)
							.build());

			if (!Utils.checkIfNullObject(tableMeta.getSortKey())) {

				AttributeType skType = AttributeType.STRING;
				if (tableMeta.getSortKey().getAttributeType().toLowerCase(Locale.ENGLISH).startsWith("num")) pkType = AttributeType.NUMBER;
				else if (tableMeta.getSortKey().getAttributeType().toLowerCase(Locale.ENGLISH).startsWith("bin")) pkType = AttributeType.BINARY;

				tableBuilder.sortKey(Attribute.builder()
						.name(tableMeta.getSortKey().getAttributeName())
						.type(skType)
						.build());
			}

			if (tableMeta.getReadCapacity() > 0) tableBuilder.readCapacity(tableMeta.getReadCapacity());
			if (tableMeta.getWriteCapacity() > 0) tableBuilder.writeCapacity(tableMeta.getWriteCapacity());

			table = new Table(this, "queue-sample-" + tableMeta.getLogicalName(),
					tableBuilder.build());

			// index creation
			for(ConfigIndex indexMeta : tableMeta.getIndexes()) {

				System.out.printf(" >> GSI ... build: [%s]%n", indexMeta.getName());

				AttributeType keyType = AttributeType.STRING;
				if (indexMeta.getHashKey().getAttributeType().toLowerCase().startsWith("num")) keyType = AttributeType.NUMBER;
				else if (indexMeta.getHashKey().getAttributeType().toLowerCase().startsWith("bin")) keyType = AttributeType.BINARY;

				GlobalSecondaryIndexProps.Builder b = GlobalSecondaryIndexProps.builder()
						.indexName(indexMeta.getName())
						.partitionKey(Attribute.builder()
								.name(indexMeta.getHashKey().getAttributeName())
								.type(keyType)
								.build());

				if (indexMeta.getReadCapacity() > 0) b.readCapacity(indexMeta.getReadCapacity());
				if (indexMeta.getWriteCapacity() > 0) b.writeCapacity(indexMeta.getWriteCapacity());
				
				if (Utils.checkIfNotNullObject(indexMeta.getSortKey())) {

					keyType = AttributeType.STRING;
					if (indexMeta.getSortKey().getAttributeType().toLowerCase().startsWith("num")) keyType = AttributeType.NUMBER;
					else if (indexMeta.getSortKey().getAttributeType().toLowerCase().startsWith("bin")) keyType = AttributeType.BINARY;

					b.sortKey(Attribute.builder()
							.name(indexMeta.getSortKey().getAttributeName())
							.type(keyType)
							.build());
				}

				table.addGlobalSecondaryIndex(b
						.build());
			}
		}
	}