如何在AWS Amplify中更改现有DynamoDB表的定价模型?

huangapple go评论65阅读模式
英文:

How Do I Change An Existing DynamoDB Table's Pricing Model in AWS Amplify?

问题

问题:AWS Amplify已经使用“按需”定价模型创建了所有我的表。

如何将“按需”更改为预配并设置读取和写入容量单位?

要求:

  1. 不能丢失表中的数据
  2. 必须按照基础设施即代码原则进行操作,我需要运行amplify push apiName来推送新的更改。
英文:

Problem: AWS Amplify has built all my tables with the "On-Demand" pricing model.

How can I change "On-Demand" to provisioned and set the read and write capacity units?

Requirements:

  1. Cannot lose data in the table
  2. Has do be done following the infrastructure as code principals, where I run amplify push apiName to push the new changes

答案1

得分: 2

无法直接使用Amplify CLI 设置 DynamoDB 表的计费模式,但您可以通过使用 CDK(Cloud Development Kit)扩展 Amplify Cloudformation 堆栈来覆盖基本功能。

使用 Storage 模块,您可以运行 amplify override storage 以创建一个 override.ts 文件,以添加自定义的 CDK TypeScript 代码,以覆盖通过 Amplify CLI 创建的存储资源的基本功能。

这将将这些更改附加到现有的 Amplify Cloudformation 堆栈,并在运行 amplify push 以配置堆栈时应用这些更改。

对于您的 DynamoDB 表,您可以自定义 dynamoDBTable 的以下属性,并覆盖您需要的属性更改。例如,要更新读取和写入容量,您将覆盖 ProvisionedThroughput 属性,并将读取和写入容量单位的值更新为所需的数量。以下是显示这一点的 TypeScript 代码示例。

import { AmplifyDDBResourceTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyDDBResourceTemplate) {
  resources.dynamoDBTable.billingMode = 'PROVISIONED';
}

官方文档链接

英文:

You cannot set the billing mode of your DynamoDB table directly using the Amplify CLI, however you can override the base functionality by extending the Amplify Cloudformation stack with the use of CDK (Cloud Development Kit).

With the Storage Module you can run amplify override storage to create an override.ts file to add custom CDK Typescript code to override the base functionality of your Storage resources created via the Amplify CLI.

This will append these changes to your existing Amplify Cloudformation stack and apply these changes when you run amplify push to provision your stack.

For your DynamoDB tables you can customize the following properties of the dynamoDBTable and override the changes of the attributes you need. For example to update the read and write capacity you would override the ProvisionedThrought property and update the Read and write capacity units value to your desired amount. Below is an example of TypeScript code which shows this.

import { AmplifyDDBResourceTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyDDBResourceTemplate) {
  resources.dynamoDBTable.billingMode = 'PROVISIONED'
}

https://docs.amplify.aws/cli/storage/override/#customize-amplify-generated-s3-resources

huangapple
  • 本文由 发表于 2023年2月9日 02:24:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390177.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定