Please tell me how to change the name of the partition key in DynamoDB created with Amplify Gen2 to any name

Please tell me how to change the name of the partition key in DynamoDB created with Amplify Gen2 to any name

Clock Icon2024.10.08

日本語版はこちら

The issue

I referred to the Amplify documentation to create a DynamoDB table with Amplify Gen2, but the name of the partition key is fixed as id.

Please tell me how to change the name of the partition key.

The solution

Please use the identifier() method.

Amplify documentation

Identifiers are defined using the .identifier() method on a model definition. Usage of the .identifier() method is optional; when it's not present, the model will automatically have a field called id of type ID that is automatically generated unless manually specified.

The following example is provided in the documentation, so please change the partition key name according to your requirements.

const schema = a.schema({
  Todo: a.model({
    todoId: a.id().required(),
    content: a.string(),
    completed: a.boolean(),
  })
  .identifier(['todoId'])
  .authorization(allow => [allow.publicApiKey()]),
});

References

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.