Open muvashi opened 1 month ago
Marking this as feature request
Thanks for adding this as a feature request. Like many companies we use Amplify to rapidly prototype an new app or feature. But when it comes to deploying we need the ability to export to CDK and deploy to multiple customer accounts using CDK. This works really well in Gen 1 using https://constructs.dev/packages/@aws-amplify/graphql-api-construct/v/1.16.0-gen2-migration-1015.0?lang=typescript. Just need the ability to do the same in Gen 2. Thanks.
Hey @muvashi and @chrisbeyer :wave: thanks for filing this and chiming in! Amplify Gen 2 is built atop of CDK and enables the ease of extensibility with existing CDK constructs and the ability to deploy with Amplify managing CDK context. We're actively thinking about additional enhancements to allow more control over CDK tooling behavior, but out of curiosity is there a particular feature you're looking for?
@muvashi you can supply the typed schema to the construct by calling .transform()
on the schema return
import { App, Stack, Duration } from "aws-cdk-lib/core"
import {
AmplifyGraphqlApi,
AmplifyGraphqlDefinition,
} from "@aws-amplify/graphql-api-construct"
import { schema } from "./schema"
const app = new App()
const stack = new Stack(app, "DemoAmplifyDataConstructWithSchema")
new AmplifyGraphqlApi(stack, "GraphqlApi", {
authorizationModes: {
apiKeyConfig: {
expires: Duration.days(30),
},
},
definition: AmplifyGraphqlDefinition.fromString(schema.transform().schema),
})
Hi @josefaidt ,
import { App, Stack, Duration } from "aws-cdk-lib/core"
import {
AmplifyGraphqlApi,
AmplifyGraphqlDefinition,
} from "@aws-amplify/graphql-api-construct"
import { schema } from "./schema"
const app = new App()
const stack = new Stack(app, "DemoAmplifyDataConstructWithSchema")
new AmplifyGraphqlApi(stack, "GraphqlApi", {
authorizationModes: {
apiKeyConfig: {
expires: Duration.days(30),
},
},
definition: AmplifyGraphqlDefinition.fromString(schema.transform().schema),
})
That's great! Thanks for providing your example. We are working with @muvashi in the AWS Support case to try and get this working in our CDK project but are getting strange errors when we try to import the schema.
Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@aws-amplify/backend/lib/index.js
We're actively thinking about additional enhancements to allow more control over CDK tooling behavior, but out of curiosity is there a particular feature you're looking for?
The main thing we really need is the ability to prototype a GraphQL API POC quickly in Amplify, then be able to export that out and use the schema in our proper CDK solution.
We typically have...
Kind regards,
Chris
Hey @chrisbeyer thanks for sharing those details! The error you're experiencing comes from the distribution of the backend package as ESM-only. You will need to set "type": "module"
in your package.json to resolve
Thanks @josefaidt . We have tried adding "type": "module" in the root /package.json in our CDK project. However we now get TypeError: Unknown file extension ".ts".
Do you have an example of this working that we could clone?
Suspect there must be something different in your tsconfig.json file as well to get this to work with CDK.
Environment information
Describe the feature
The requirement is to export the Amplify Gen 2 application and import and use in CDK. It is supported in Gen1 :-
https://docs.amplify.aws/gen1/react/tools/cli/usage/export-to-cdk/
But there does not seem to be any documentation on how to do this with Gen 2.
If this is not supported, can we somehow pass Amplify gen2 data schema under definition while using Amplify GraphQL API Construct.
https://constructs.dev/packages/@aws-amplify/graphql-api-construct/v/1.16.0-gen2-migration-1015.0?lang=typescript
Use case
.