Amplify-cli: Can't connect DynamoDB with my function

Created on 24 Jan 2020  路  9Comments  路  Source: aws-amplify/amplify-cli

I create DynamoDB database use command
amplify add api
and the when I try create function what will be working with my DynamoDB i got the error
-There are no DynamoDB resources configured in your project currently
Steps for reproduce:
amplify add api
amplify add function updateDynamoDB

? Provide a friendly name for your resource to be used as a label for this category in the project: updateDynamoDB
? Provide the AWS Lambda function name: updateDynamoDB
? Choose the function template that you want to use: CRUD function for Amazon DynamoDB table (Integration with Amazon API Gateway and Amazon DynamoDB)
? Choose a DynamoDB data source option Use DynamoDB table configured in the current Amplify project
There are no DynamoDB resources configured in your project currently

functions pending-triage

Most helpful comment

@andrestone how doesn't it make sense?
AppSync is very to hard to do business logic on, because of that VTL stuff, and because all of us are mostly JavaScript developers we are much more comfortable writing lambda functions in JS.

It makes perfect sense that you could create tables using the @model directive and then use those tables in other lambda functions/REST APIs

All 9 comments

@dimonchik-com "amplify add api" - did you add REST or GraphQL API?
Which DynamoDB tables do you expect to see there?

@dimonchik-com "amplify add api" - did you add REST or GraphQL API?
Which DynamoDB tables do you expect to see there?

GraphQL API
I expect see possibility to work with DynamoDB

I'm afraid this workflow isn't supported, and honestly it doesn't make much sense to me.

The add api workflow is built for you to interact with DynamoDB via API calls (AppSync / GraphQL). In the context of amplify-cli, it doesn't make sense that you add an API and then expect that any other given command would "connect" to any underlying resource.

Of course, you can still make a Lambda function that will use conventional AWS SDKs to perform CRUD operations on your API data source (DynamoDB in this case), but it should be really up to you to set it manually, IMHO.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.html

@andrestone how doesn't it make sense?
AppSync is very to hard to do business logic on, because of that VTL stuff, and because all of us are mostly JavaScript developers we are much more comfortable writing lambda functions in JS.

It makes perfect sense that you could create tables using the @model directive and then use those tables in other lambda functions/REST APIs

It makes perfect sense that you could create tables using the @model directive and then use those tables in other lambda functions/REST APIs

Sure, it does. But the issue here is about accessing a DynamoDB table that, as I said, in the context of amplify-cli, is behind an AppSync API. It would make sense for me if this was a feature request to reduce friction / implement a higher level API to interact with the AppSync (such as an ORM layer, for example).

@andrestone That would be great if they introduced some sort high level interaction layer with AppSync but I don't see it happening any time soon as it will probably take a long time to develop and there aren't any signs showing that it is currently in development (or if they are even thinking about it).
The ability to interact with DynamoDB tables created by GraphQL API in a lambda function seems much easier to implement, it amazes me that this functionality is still not available - seems like a common use case for web devs who don't want to mess with VTL

There is nothing preventing you to do that. If you need no mapping and simply want to access your table it's as simple as using the SDK inside your lambda.

@andrestone I would still like to use GraphQL for simple mutations, and the auto-generated queries are great and easy to use. It's just difficult to add business logic with the VTL language.

as @idanlo said, a lot of devlopers are much more confortable with javascript than vtl...
I would like to access a dynamodb table in a lambda function. This table was generated using the @model directive in a graphqlAPI resource.
How can i get this dynamo table name, to be able to access it?

Was this page helpful?
0 / 5 - 0 ratings