Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum
* Which Category is your question related to? *
amplify graphql api/dynamodb
* What AWS Services are you utilizing? *
dynamodb/appsync
* Provide additional details e.g. code snippets *
I've read all the existing open issues and tried repeatedly. I'm new to amplify specifically.
I have an existing angular project, the project already uses mqtt over websockets for backend connections to IoT Core and SQS. I'm trying to migrate over to amplify/appsync for a graphql API and cognito. I've figured out how to use an existing user pool for cognito, but for the life of me I cannot get amplify add api > graphql to let me use an existing dynamodb table. I DO NOT WANT amplify to control the databases. I have existing databases and will not migrate the data to an amplify controlled database. I'm using multi-env which deploys into multi-account and need to build a schema for 3/4 existing dynamodb tables per environment.
How do I do this? Seems pretty simple to me logistically. Let me just specify the DynamoDB table I want to use with the graphql auto-generated schema. Just tell me to make sure streaming is enabled and provide the table and streaming ARN.
@Einstein42 Amplify CLI provides a rich set of scaffolding functionality to simplify customers' work. Amplify is a "convention over configuration" tool, which cannot be aimed easily for a BYOD (bring your own database) scenario, but I think Amplify CLI could still help you.
The solution I've in my mind is using the CLI to create your API and then author your GraphQL schema as you want to shape it. If you want full control over your data then the CLI supported way is using Custom Resolvers and DataSources in your Custom CloudFormation templates.
If you're new to Amplify I suggest to follow the tutorials and give Amplify a try to build and manage your data by using the @model and @auth directives. That would give you a good understanding where the CLI provides the value and could help you to author your custom resolvers.
You can pick VTL based resolvers, HTTP ones if you want to expose GraphQL but consume an existing API behind the scenes or you can go with Lambda resolvers. These options are all supported by the CLI.
I've read through all the tutorials and even attempted them. Forgive my ignorance but I'm just not seeing how the Resolvers know which database they are talking to? When I amplify add api > graphql, I see the build directory and all that, I've tried modifying the cloudformation templates but they are just overwritten on push. Where is it referencing the DB and how can I override that like I can on auth? So even if I create a custom resolver and datasource in custom cloudformation, how does it know the ARN's of the database in question?
When you create an AppSync DataSource it has a DynamoDBConfig property where you can provide the name - not the arn - of the DynamoDB table you already have.
@attilah correct, but I meant from an amplify perspective. Again forgive my ignorance. I know AppSync fairly well, just not the amplify cli.
amplify add api > graphql > do you have a schema, N > it creates all the config/artifacts in the amplify/backend/api/
I look through all the files in that folder from schema.graphql to all the build files. Where does it know that
type MyType @model {
id: ID!
}
equates to a specific table name? Does it use the api/
Can I modify that cloudformation-template.json without it being overwritten like the rest of the build directory is?
If not and I can just use the custom stacks to create everything. How do I make sure that the existing cf templates in build/ aren't used? There is no way that I found when doing amplify api add to create a blank api with no schema and just manually add it before building.
Maybe I'm confused, either way I appreciate your direction.
If you opt-in for custom you cannot use any of the CLI supplied GraphQL directives for your use case. However you can still have CLI to do the deployment and management of all the resources you are creating by hand for your API.
When you've no @model or anything in the templates you'll only have the resources you add and the AppSync API itself.
How do I 'opt-in'. Just modify the cft? It crashed when I tried to not have anything in the schema.
I've been basically asking the same question(s) in #1970. I would like to use @model to generate all VTL files _and_ connect to a custom table.
@Einstein42 Which CFT are you trying to change? I'm interested in the 'opt-in' as well.
When I use amplify api gql-compile it generates the code I need including the VTL's. I'd like to change the CFT but don't want Amplify to change anything with regard to that table.
Can I just add another CFT json (with the same name) to the stacks folder to override the generated one?
@Einstein42 sorry if I was using a wrong phrase, under 'opt-in' I meant that opt-in to using CLI features like @model, @auth.
You can define your types, queries, mutations in the GraphQL file and then create the CFN resources that AppSync requires as Custom Resources.
Closing due to no response from the issue creator.
Most helpful comment
I've been basically asking the same question(s) in #1970. I would like to use
@modelto generate all VTL files _and_ connect to a custom table.@Einstein42 Which CFT are you trying to change? I'm interested in the 'opt-in' as well.
When I use
amplify api gql-compileit generates the code I need including the VTL's. I'd like to change the CFT but don't want Amplify to change anything with regard to that table.Can I just add another CFT json (with the same name) to the
stacksfolder to override the generated one?