aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

"Failed to update project" after cloud-api configuration with 'Create CRUD API for an existing Amazon DynamoDB table' #522

Closed ipuris closed 6 years ago

ipuris commented 6 years ago

I'm using AWS Mobile Hub and AWS Amplify for my React Native project. I successfully have integrated User Sign-in (Amazon Cognito), Cloud Logic (Amazon API Gateway and AWS Lambda), and NoSQL Database (Amazon DynamoDB).

I have tried to create CRUD API using command-line tool according to documentation in https://docs.aws.amazon.com/aws-mobile/latest/developerguide/react-native-access-databases.html

All steps have done successfully, but the last step, awsmobile push gave me an following error.

Failed to update project lumi
{ BadRequestException: Malformed project configuration files. Unable to parse YAML file awsmobile-cli-project/mobile-hub-project.yml Error near line 16: Unterminated inline value

The line 16 in mobile-hub-project.yml is around paths field. After the awsmobile cloud-api configure, the file is changed into:

paths:
          /things: !com.amazonaws.mobilehub.v0.Function 
            name: thingsHandler
            codeFilename: tag:yaml.org,2002:js/undefined ''
            handler: index.handler
            enableCORS: tag:yaml.org,2002:js/undefined ''
            runtime: nodejs6.10
            environment: {}
          '/things/{proxy+}': !com.amazonaws.mobilehub.v0.Function 
            name: thingsHandler
            codeFilename: tag:yaml.org,2002:js/undefined ''
            handler: index.handler
            enableCORS: tag:yaml.org,2002:js/undefined ''
            runtime: nodejs6.10
            environment: {}

where the original file is:

        paths:
          /things: !com.amazonaws.mobilehub.v0.Function 
            description: 'Handler for calls to resource path : /things/{proxy+}'
            environment: {}
            handler: index.handler
            hashcode: Pj6eZDjB+pTLFXuSZjkbZZueZVGd9Kh3nTwjMsU1pAg=
            memorySize: '128'
            modified: '2018-03-26T06:04:44.705+0000'
            name: thingsHandler
            runtime: nodejs6.10
            timeout: '3'
            version: UFr90.5HK9sJdX2dVf9TsWNA1uV5qyAx
          '/things/{proxy+}': !com.amazonaws.mobilehub.v0.Function 
            description: 'Handler for calls to resource path : /things/{proxy+}'
            environment: {}
            handler: index.handler
            hashcode: Pj6eZDjB+pTLFXuSZjkbZZueZVGd9Kh3nTwjMsU1pAg=
            memorySize: '128'
            modified: '2018-03-26T06:04:44.705+0000'
            name: thingsHandler
            runtime: nodejs6.10
            timeout: '3'
            version: wVryIKsxHPdu2SVbnYGaI3ce4f4VL3rA

I found that codeFilename and enableCORS fields are created, and that fields are ended with ''. After I entered awsmobile push in console, the fields are changed again like:

        paths:
          /things: !com.amazonaws.mobilehub.v0.Function 
            name: thingsHandler
            codeFilename: uploads/thingsHandler-20180326182848.zip
            handler: index.handler
            enableCORS: 'tag:yaml.org,2002:js/undefined '''''
            runtime: nodejs6.10
            environment: {}
          '/things/{proxy+}': !com.amazonaws.mobilehub.v0.Function 
            name: thingsHandler
            codeFilename: uploads/thingsHandler-20180326182848.zip
            handler: index.handler
            enableCORS: 'tag:yaml.org,2002:js/undefined '''''
            runtime: nodejs6.10
            environment: {}

Now two single quote in the end of codeFilename field has gone, but there are weird four single quotes in the end of enableCORS. I think there are some parsing error when configuring cloud-api and awsmobile push, but I'm not sure what is the reason of this error. Please give me an advice if you have any idea.


My full configuration for cloud-api is:

$ awsmobile cloud-api configure

This feature will create an API using Amazon API Gateway and AWS Lambda. You can optionally have the lambda function perform CRUD operations against your Amazon DynamoDB table.

? Select from one of the choices below. Create CRUD API for an existing Amazon DynamoDB table
? Select Amazon DynamoDB table to connect to a CRUD API feed
? Restrict API access to signed-in users Yes
Adding lambda function code on:
/Users/ipuris/Developer/lumi/awsmobilejs/backend/cloud-api/feed/
...
Path to be used on API for get and remove an object should be like:
/feed/object/:babyId

Path to be used on API for list objects on get method should be like:
/feed

JSON to be used as data on put request should be like:
{
  "babyId": "INSERT VALUE HERE",
  "category": "INSERT VALUE HERE",
  "creationDate": "INSERT VALUE HERE",
  "details": "INSERT VALUE HERE",
  "endDate": "INSERT VALUE HERE",
  "startDate": "INSERT VALUE HERE",
  "tags": "INSERT VALUE HERE"
}
To test the api from the command line (after awsmobile push) use this commands
awsmobile cloud-api invoke feedCRUD <method> <path> [init]

and the full error message is:

$ awsmobile push

checking for local backend changes
   building cloud-api
      zipping feed
      zipping thingsHandler
   done
   generating backend project content
   done
backend build artifacts are saved at:
/Users/ipuris/Developer/lumi/awsmobilejs/.awsmobile/backend-build

preparing for backend project update: lumi
   uploading feed-20180326175422.zip
   uploading thingsHandler-20180326175422.zip
   upload Successful  thingsHandler-20180326175422.zip
   upload Successful  feed-20180326175422.zip
done

updating backend project: lumi
Failed to update project lumi
{ BadRequestException: Malformed project configuration files. Unable to parse YAML file awsmobile-cli-project/mobile-hub-project.yml Error near line 16: Unterminated inline value
    at Object.extractError (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.extractError (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)
    at Request.callListeners (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/usr/local/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:685:12)
  message: 'Malformed project configuration files. Unable to parse YAML file awsmobile-cli-project/mobile-hub-project.yml Error near line 16: Unterminated inline value',
  code: 'BadRequestException',
  time: 2018-03-26T08:55:02.327Z,
  requestId: '5e5d8529-30d3-11e8-8692-f56c6f73a3e3',
  statusCode: 400,
  retryable: false,
  retryDelay: 18.309554331243994 }
elorzafe commented 6 years ago

Hi @ipuris did you create the your first cloud api using mobilehub console or the cli?

elorzafe commented 6 years ago

I have reproduced the bug. I will send a PR to fix this

elorzafe commented 6 years ago

This issue was fixed with version 1.1.2

github-actions[bot] commented 3 years ago

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 or Discussions for those types of questions.