You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: daprdocs/content/en/reference/components-reference/supported-state-stores/setup-dynamodb.md
+87-3
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ spec:
21
21
version: v1
22
22
metadata:
23
23
- name: table
24
-
value: "mytable"
24
+
value: "Contracts"
25
25
- name: accessKey
26
26
value: "AKIAIOSFODNN7EXAMPLE"# Optional
27
27
- name: secretKey
@@ -34,6 +34,8 @@ spec:
34
34
value: "myTOKEN"# Optional
35
35
- name: ttlAttributeName
36
36
value: "expiresAt"# Optional
37
+
- name: partitionKey
38
+
value: "ContractID"# Optional
37
39
```
38
40
39
41
{{% alert title="Warning" color="warning" %}}
@@ -42,19 +44,20 @@ The above example uses secrets as plain strings. It is recommended to use a secr
42
44
43
45
## Primary Key
44
46
45
-
In order to use DynamoDB as a Dapr state store, the table must have a primary key named `key`.
47
+
In order to use DynamoDB as a Dapr state store, the table must have a primary key named `key`. See the section [Partition Keys]({{< ref "setup-dynamodb.md#partition-keys" >}}) for an option to change this behavior.
| table | Y | name of the DynamoDB table to use | `"mytable"`
53
+
| table | Y | name of the DynamoDB table to use | `"Contracts"`
52
54
| accessKey | N | ID of the AWS account with appropriate permissions to SNS and SQS. Can be `secretKeyRef` to use a secret reference | `"AKIAIOSFODNN7EXAMPLE"`
53
55
| secretKey | N | Secret for the AWS user. Can be `secretKeyRef` to use a secret reference |`"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"`
54
56
| region | N | The AWS region to the instance. See this page for valid regions: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html. Ensure that DynamoDB are available in that region.| `"us-east-1"`
55
57
| endpoint | N |AWS endpoint for the component to use. Only used for local development. The `endpoint` is unncessary when running against production AWS | `"http://localhost:4566"`
56
58
| sessionToken | N |AWS session token to use. A session token is only required if you are using temporary security credentials. | `"TOKEN"`
57
59
| ttlAttributeName | N |The table attribute name which should be used for TTL. | `"expiresAt"`
60
+
| partitionKey | N |The table primary key or partition key attribute name. This field is used to replace the default primary key attribute name `"key"`. See the section [Partition Keys]({{< ref "setup-dynamodb.md#partition-keys" >}}). | `"ContractID"`
58
61
59
62
{{% alert title="Important" color="warning" %}}
60
63
When running the Dapr sidecar (daprd) with your application on EKS (AWS Kubernetes), if you're using a node/pod that has already been attached to an IAM policy defining access to AWS resources, you **must not** provide AWS access-key, secret-key, and tokens in the definition of the component spec you're using.
@@ -70,6 +73,87 @@ In order to use DynamoDB TTL feature, you must enable TTL on your table and defi
70
73
The attribute name must be defined in the `ttlAttributeName` field.
71
74
See official [AWS docs](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html).
72
75
76
+
## Partition Keys
77
+
78
+
By default, the DynamoDB state store component uses the table attribute name `key` as primary/partition key in the DynamoDB table.
79
+
This can be overridden by specifying a metadata field in the component configuration with a key of `partitionKey` and a value of the desired attribute name.
80
+
81
+
To learn more about DynamoDB primary/partition keys, read the [AWS DynamoDB Developer Guide.](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey)
82
+
83
+
The following `statestore.yaml` file shows how to configure the DynamoDB state store component to use the partition key attribute name of `ContractID`:
84
+
85
+
```yaml
86
+
apiVersion: dapr.io/v1alpha1
87
+
kind: Component
88
+
metadata:
89
+
name: statestore
90
+
spec:
91
+
type: state.aws.dynamodb
92
+
version: v1
93
+
metadata:
94
+
- name: table
95
+
value: "Contracts"
96
+
- name: partitionKey
97
+
value: "ContractID"
98
+
```
99
+
100
+
The above component specification assumes the following DynamoDB Table Layout:
101
+
102
+
```console
103
+
{
104
+
"Table": {
105
+
"AttributeDefinitions": [
106
+
{
107
+
"AttributeName": "ContractID",
108
+
"AttributeType": "S"
109
+
}
110
+
],
111
+
"TableName": "Contracts",
112
+
"KeySchema": [
113
+
{
114
+
"AttributeName": "ContractID",
115
+
"KeyType": "HASH"
116
+
}
117
+
],
118
+
}
119
+
```
120
+
121
+
The following operation passes `"A12345"` as the value for `key`, and based on the component specification provided above, the Dapr runtime will replace the `key` attribute name
122
+
with `ContractID` as the Partition/Primary Key sent to DynamoDB:
123
+
124
+
```shell
125
+
$ dapr run --app-id contractsprocessing --app-port ...
126
+
127
+
$ curl -X POST http://localhost:3500/v1.0/state/<store_name> \
128
+
-H "Content-Type: application/json"
129
+
-d '[
130
+
{
131
+
"key": "A12345",
132
+
"value": "Dapr Contract"
133
+
}
134
+
]'
135
+
```
136
+
137
+
The following AWS CLI Command displays the contents of the DynamoDB `Contracts` table:
0 commit comments