You can make
@index updates on one "amplify push". Under the hood, Amplify CLI needs to locally sequence multiple individual deployments to your DynamoDB table because each Global Secondary Index (GSI), managed by
@index, change requires time to create the new index.
If your deployment fails locally when updating multiple GSIs, you'll have the ability to run:
amplify push --iterative-rollbackto rollback the last-known-good state
amplify push --forceto rollback the last-known-good state and try redeploying your changes again using.
1Attempting to mutate more than 1 global secondary index at the same time.
If you're running into the error above during
amplify push, it is likely that you don't have this feature enabled. To enable multiple GSI updates, set the "enableIterativeGsiUpdates" feature flag to true in your
When you add
@searchable to a
@model type with existing data, then you need to backfill the OpenSearch index. Download the following Python script to help you backfill your OpenSearch index:
The script creates an event stream of your DynamoDB records and sends them to your OpenSearch Index. Execute the script with the following parameters to initiate the backfill:
|DynamoDB table region. See AWS Regions for available options||Yes|
|DynamoDB table name. Format: ||Yes|
|ARN of the "DynamoDB to OpenSearch streaming" Lambda function. Format: ||Yes|
|ARN of the DynamoDB table stream. Format: ||Yes|
|AWS Access Key ID. This is used to authenticate with your AWS account in case no local AWS profile is set up.||No|
|AWS Secret Access Key. This is used to authenticate with your AWS account in case no local AWS profile is set up.||No|
|AWS Session Token. This is used to authenticate with your AWS account in case no local AWS profile is set up.||No|
In the example below, the
Post table data in
us-west-2 gets backfilled in the OpenSearch index.
1python3 ddb_to_es.py \2 --rn 'us-west-2' \ # Use the region in which your table and OpenSearch domain reside3 --tn 'Post-XXXX-dev' \ # Table name4 --lf 'arn:aws:lambda:us-west-2:<...>:function:amplify-<...>-OpenSearchStreamingLambd-<...>' \ # Lambda function ARN, find the DynamoDB to OpenSearch streaming functions, copy entire ARN5 --esarn 'arn:aws:dynamodb:us-west-2:<...>:table/Post-<...>/stream/2019-20-03T00:00:00.350' # Event source ARN, copy the full DynamoDB table ARN
When you add an
@index directive with 2 or more sort key fields, you will need to backfill the new composite sort key for existing data. With
@index(sortKeyFields: ["status", "date"]), you will need to backfill the
status#date field with composite key values made up of each object's
date fields joined by a
#. You do not need to backfill data for
@index directives with zero to one sort key field(s).
If you have increased the soft limit of GSI per table in DynamoDB beyond 20, then iterative deployments will fail with the following warning.
1DynamoDB <Table Name> can have max of 20 GSIs.2To disable this check, use the --disable-gsi-limit-check option.
In order to disable this behavior, update your deploy scripts or ci commands to include the
--disable-gsi-limit-check option to circumvent this validation during pushes.
1amplify push --disable-gsi-limit-check