Amplify-cli: How to reference table (or other resources) within CustomResources template?

Created on 23 May 2019  路  4Comments  路  Source: aws-amplify/amplify-cli

* Which Category is your question related to? *
API

* What AWS Services are you utilizing? *
GraphQL, DynamoDB

* Provide additional details e.g. code snippets *

Looking here: https://aws-amplify.github.io/docs/cli/graphql?sdk=js#add-a-custom-resolver-that-targets-a-dynamodb-table-from-model

In that example, there is a CommentTable referenced in the example - how would I utilize this to put the actual table name in there in a multi-environment scenario? I've tried adding parameters without success. What is the recipe for utilizing the resources you already have in place within CustomResources?

graphql-transformer question

All 4 comments

The table name is in the form [Name]-[AppSyncApiId]-[env]. If you are in the CustomResources.json template, then you are lucky, the AppSyncApiId is passed as a parameter. So, you can use something like this, assuming my table's name is Courses:

"Fn::Sub": "Courses-${AppSyncApiId}-${env}"

Hope it helps

I will give this a try, thank you.

@mwarger, even better, we can use the AppSyncApiId to import outputs of other stacks

"Fn::ImportValue": {
  "Fn::Sub": "${AppSyncApiId}:GetAtt:CoursesTable:Name"
}

This way we don't have to deal with how is the form of the name of the table. It returns the table's name no matter how it was implemented.

We can also import, for example, the StreamArn

"Fn::ImportValue": {
  "Fn::Sub": "${AppSyncApiId}:GetAtt:CoursesTable:StreamArn"
}

Hope it helps

I was able to get this working, thank you!

Was this page helpful?
0 / 5 - 0 ratings