Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How in terraform dynamodb specify composite primary key (hashkey)

My goal is to create terraform resource "aws_dynamodb_table" with composite primary key as it describes in AWS documentation.

Based on Terraform documentation it allows for hash_key to have only a single Attribute name. How can I have a hash_key made by multiple attributes?

like image 994
Maxim Vershinin Avatar asked Sep 06 '25 03:09

Maxim Vershinin


1 Answers

Use the range_key terraform argument, which is the sort key on DynamoDB. That way you'll get a composite key as stated in the AWS documentation. The hash_key is referred as Partition key.

Partition key and sort key – Referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key.

If you want to query among other attributes, try with a local_secondary_index.

like image 178
Daniel Montoya Avatar answered Sep 07 '25 21:09

Daniel Montoya