Skip to content

Conversation

@dpilch
Copy link
Contributor

@dpilch dpilch commented Oct 30, 2024

Description of changes

Add feature to import DDB tables for gen 2 migration in experimental state.

List of all PR to feature/gen2-migration:
https://github.com/aws-amplify/amplify-category-api/pulls?q=is%3Apr+is%3Aclosed+base%3Afeature%2Fgen2-migration+

Documentation has not been updated. This will be done with the official release of migrations.

CDK / CloudFormation Parameters Changed
  • Add overrideIndexName to @belongsTo to change the name of the GSI that is automatically created with references.
  • New data source strategy: IMPORTED_AMPLIFY_TABLE.
  • New construct prop: importedAmplifyDynamoDBTableMap.

importedAmplifyDynamoDBTableMap will define a mapping of model name to imported table name. All models defined with the IMPORTED_AMPLIFY_TABLE should have a matching key in the importedAmplifyDynamoDBTableMap prop.

import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import {
  AmplifyGraphqlApi,
  AmplifyGraphqlDefinition,
} from "@aws-amplify/graphql-api-construct";
import * as path from "path";

export class BackendStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const amplifyApi = new AmplifyGraphqlApi(this, "MyNewApi", {
      definition: AmplifyGraphqlDefinition.combine([
        AmplifyGraphqlDefinition.fromString(
          `
            type Todo @model @auth(rules: [{ allow: public }]) {
              title: String
            }
          `,
          {
            dbType: "DYNAMODB",
            provisionStrategy: "DEFAULT",
          },
        ),
        AmplifyGraphqlDefinition.fromString(
          `
            type Blog @model @auth(rules: [{ allow: public }]) {
              title: String
              content: String
              authors: [String]
            }
          `,
          {
            dbType: "DYNAMODB",
            provisionStrategy: "IMPORTED_AMPLIFY_TABLE",
          },
        ),
      ]),
      importedAmplifyDynamoDBTableMap: {
        // existing table
        Blog: 'Blog-xxxx-NONE',
      },
      authorizationModes: {
        defaultAuthorizationMode: "API_KEY",
        apiKeyConfig: {
          expires: cdk.Duration.days(30),
        },
      },
    });
  }
}

Issue #, if available

N/A

Description of how you validated changes

  • Unit tests
  • E2E tests
    • PredictionsTransformerV2Tests.e2e.test.ts is passing locally

Checklist

  • PR description included
  • yarn test passes
  • E2E test run linked
  • Tests are changed or added
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Any CDK or CloudFormation parameter changes are called out explicitly

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dpilch dpilch marked this pull request as ready for review November 6, 2024 20:18
@dpilch dpilch requested review from a team as code owners November 6, 2024 20:18
@dpilch dpilch changed the title Feature/gen2 migration feat: add imported DDB tables for gen 2 migration in experimental state Nov 6, 2024
@dpilch dpilch merged commit 0c415b3 into main Nov 6, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants