amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

DynamoDB table name is not correct in the lambda function when using amplify add api

Open ranef opened this issue 8 years ago • 8 comments

Describe the bug I used: amplify add api And followed the guided steps including the part of creating the DynamoDB table The bug is although I changed the table name from the suggested default “dynamo37579910” to “items”, the dynamo table itself was crated with the updated name but in the generated lambda code the table name was not changed (see screenshot) After I manually updated the lambda code under .amplify/backend/function/myfunctionName/src/app.js it started to work

To Reproduce Steps to reproduce the behavior:

  1. amplify add api
  2. Select the REST option
  3. Choose Create a new lambda function
  4. Choose CRUD function for Amazon DynamoDB table (Integration with Amazon API Gateway and Amazon DynamoDB)
  5. When prompted for the dynamoDB table name change it from the suggested default to a custom name (e.g. items)
  6. Continue with the rest of the flow till the end and push the changes

Expected behavior The dynamoDB table is created with the provided custom name (e.g. items) - OK The same custom name is updated in the lambda function ./amplify/backend/function/myfunctionName/src/app.js in the line 17 let tableName = "items"; - Not OK

Screenshots screen shot 2018-09-27 at 12 18 17 pm

Desktop:

  • OS: MacOS HighSierra
  • Browser: chrome
  • Version: 69.0.3497.100 (Official Build) (64-bit)

Additional context

ranef avatar Sep 27 '18 11:09 ranef

@ranef Unforutnately, i wasn't able to reproduce this. Here's my CLI flow: screen shot 2018-09-28 at 1 00 49 pm

Here's my lambda function generated with the custom dynamo table name: screen shot 2018-09-28 at 1 00 57 pm

Is there something different that I'm doing in the flow whihc is different from yours?

kaustavghosh06 avatar Sep 28 '18 20:09 kaustavghosh06

@ranef Not able to reproduce this issue. Please feel free to re-open this if the problem still persists.

kaustavghosh06 avatar Oct 09 '18 02:10 kaustavghosh06

@kaustavghosh06

I have come across the same issue using amplify version 0.1.45.

The problem only occurs if you use a different friendly name for the DynamoDB category to the name of the table.

The generated function is using the friendly name of the category instead of the name of the table.

Command sequence to reproduce:

amplify api add
? Please select from one of the below mentioned services: REST
? Provide a friendly name for your resource to be used as a label for this category in the project: dbrest
? Provide a path (e.g., /items) /items
? Choose a Lambda source Create a new Lambda function
? Provide a friendly name for your resource to be used as a label for this category in the project: dbrestfunction
? Provide the AWS Lambda function name: dbrestfunction
? 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 Create a new DynamoDB table

? Please provide a friendly name for your resource that will be used to label this category in the project: categoryname
? Please provide table name: tablename
? What would you like to name this column: id
? Please choose the data type: string
? Would you like to add another column? No
? Please choose partition key for the table: id
? Do you want to add a sort key to your table? No
? Do you want to add global secondary indexes to your table? No
Succesfully added DynamoDb table locally
? Do you want to edit the local lambda function now? No
Succesfully added the Lambda function locally
? Restrict API access No
? Do you want to add another path? No
Successfully added resource dbrest locally

The two lines from above that trigger the bug are:

? Please provide a friendly name for your resource that will be used to label this category in the project: categoryname
? Please provide table name: tablename

The generated function amplify/backend/function/dbrestfunction/src/app.js has the following code:

const dynamodb = new AWS.DynamoDB.DocumentClient();

let tableName = "categoryname";

This should instead be:

let tableName = "tablename";

craigmalone avatar Feb 07 '19 04:02 craigmalone

We are on AWS Amplify v1.12.0 and still remains the same error! =(

wellmmer avatar Aug 16 '19 02:08 wellmmer

I love AWS Amplify but I am still facing this issue. How is this not a big deal and why is it closed? Is there any workaround at least?

iamtekeste avatar Aug 20 '19 15:08 iamtekeste

@iamtekeste You can always modify your Lambda function located in ‘amplify/backend/function/fn-name/src/app.js’ and change the ‘let tablenname’ parameter to any table you want to reference from the Lambda function.

kaustavghosh06 avatar Aug 20 '19 15:08 kaustavghosh06

Thank you @kaustavghosh06 for that workaround!

iamtekeste avatar Aug 20 '19 15:08 iamtekeste

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 27 '21 03:05 github-actions[bot]