Skip to main content

Provision a DynamoDB table

We can now define a real DynamoDB table as a Kubernetes resource. Take a look at the manifest:

~/environment/eks-workshop/modules/fastpaths/eks-capabilities/ack/dynamodb/table.yaml
apiVersion: dynamodb.services.k8s.aws/v1alpha1
kind: Table
metadata:
name: items
namespace: carts
spec:
tableName: ${EKS_CLUSTER_AUTO_NAME}-carts-fastpath
billingMode: PAY_PER_REQUEST
keySchema:
- attributeName: id
keyType: HASH
attributeDefinitions:
- attributeName: id
attributeType: "S"
- attributeName: customerId
attributeType: "S"
globalSecondaryIndexes:
- indexName: idx_global_customerId
keySchema:
- attributeName: customerId
keyType: HASH
- attributeName: id
keyType: RANGE
projection:
projectionType: "ALL"
A

Uses the ACK DynamoDB controller's Table custom resource.

B

Names the table after the cluster (${EKS_CLUSTER_AUTO_NAME}-carts-fastpath) so parallel workshop runs don't collide.

C

Uses on-demand pricing.

D

Defines the partition key schema, matching what the carts service expects.

E

Adds a global secondary index on customerId so the service can query carts by customer.

info

The YAML closely mirrors the DynamoDB CreateTable API. Anything you can express through the API is expressible here.

Apply the manifest:

~$kubectl kustomize ~/environment/eks-workshop/modules/fastpaths/eks-capabilities/ack/dynamodb \
| envsubst | kubectl apply -f -
table.dynamodb.services.k8s.aws/items created

The capability's DynamoDB controller picks up the new Table resource and provisions the corresponding AWS resource. Wait for the ACK.ResourceSynced condition, which is how every ACK resource signals it has reconciled successfully:

~$kubectl wait table.dynamodb.services.k8s.aws items \
-n carts --for=condition=ACK.ResourceSynced --timeout=10m
table.dynamodb.services.k8s.aws/items condition met

Inspect the resource status:

~$kubectl get table.dynamodb.services.k8s.aws items -n carts \
-o jsonpath='{.status.tableStatus}{"\n"}'
ACTIVE

Finally, confirm the table exists in AWS:

~$aws dynamodb describe-table \
--table-name "$EKS_CAP_DDB_TABLE" \
--query 'Table.TableStatus' --output text
ACTIVE

We've created a real DynamoDB table without ever leaving the Kubernetes API. The capability handled both the controller infrastructure and the IAM permissions needed to call the DynamoDB API.