Skip to content

[Feature Request]Add an option of ProjectionType for Dynamodb Global Secondary Index (Amplify Gen2) #2945

Open
@MyNameIsTakenOMG

Description

@MyNameIsTakenOMG

Environment information

System:
  OS: macOS 14.6.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 122.77 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.20.4 - /usr/local/bin/node
  Yarn: 1.22.19 - /opt/homebrew/bin/yarn
  npm: 10.7.0 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.0
  @aws-amplify/backend: 1.1.1
  @aws-amplify/backend-auth: 1.1.3
  @aws-amplify/backend-cli: 1.2.5
  @aws-amplify/backend-data: 1.1.2
  @aws-amplify/backend-deployer: 1.1.0
  @aws-amplify/backend-function: 1.3.4
  @aws-amplify/backend-output-schemas: 1.2.0
  @aws-amplify/backend-output-storage: 1.1.1
  @aws-amplify/backend-secret: 1.1.0
  @aws-amplify/backend-storage: 1.1.2
  @aws-amplify/cli-core: 1.1.2
  @aws-amplify/client-config: 1.2.1
  @aws-amplify/deployed-backend-client: 1.4.0
  @aws-amplify/form-generator: 1.0.1
  @aws-amplify/model-generator: 1.0.5
  @aws-amplify/platform-core: 1.0.6
  @aws-amplify/plugin-types: 1.2.1
  @aws-amplify/sandbox: 1.2.0
  @aws-amplify/schema-generator: 1.2.1
  aws-amplify: 6.5.2
  aws-cdk: 2.154.1
  aws-cdk-lib: 2.154.1
  typescript: 5.5.3
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the feature

When customizing secondary indexes with .secondaryIndexes((index) => [index("GSI-pk")]) by following the documentation, we need a way to configure the ProjectionType(KEYS_ONLY, INCLUDE , or ALL), for example, add a method .projection(<type>, [fields]?), so that we could specify which fields would be projected into our GSI tables.

By the time I am writing, the amplify backend will provision our GSIs with ProjectionType of ALL, which in my opinion is not recommended, because it might incur higher storage costs and could slow down write operations on the base table since updates will be replicated across all GSIs.

Use case

In my case, I am designing my table following one-table design, which contains multiple GSI tables. However, as I mentioned above, right now the amplify backend would provision GSIs with projectionType of ALL, which means my table data would be replicated for multiple times, which could incur a lot costs.

In addition, the projectionType cannot be modified once the GSI is provisioned, which means I either have to manually delete those GSIs and re-create them with proper ProjectionType or create those GSIs myself via aws console, cli, scripts, or custom resource

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions