Deploy the APIs

From @jayair on Thu May 11 2017 21:53:55 GMT+0000 (UTC)

@mitchallen It might be because you have an older version of the cli. Here is mine:

$ aws --version
aws-cli/1.11.40 Python/2.7.10 Darwin/15.6.0 botocore/1.5.3

From @mitchallen on Thu May 11 2017 21:59:19 GMT+0000 (UTC)

This upgrade command didnā€™t do what I thought it would:

$ pip install --upgrade --user awscli

So I went with the nuclear option:

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws aws --version
aws-cli/1.11.85 Python/2.7.11 Darwin/15.6.0 botocore/1.5.48

Now the command works.

Thanks.

From @martinsaporiti on Tue May 23 2017 22:42:36 GMT+0000 (UTC)

HI!, me again.
Well, when I run serverless deploy the following occurs:

Serverless: Packing external modules: babel-runtime@^6.23.0, uuid@^3.0.1
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (1.03 MB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
........................Serverless: Deployment failed!
 
  Serverless Error ---------------------------------------
 
     An error occurred while provisioning your stack: 2Underscorewk567VfjNLambdaPermissionApiGateway
     - Unable to parse HTTP response content.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless
 
  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       6.9.4
     Serverless Version: 1.13.2

Someone can help me? I donā€™t have idea why happen this.
Thank you very much.

From @frittate on Thu May 25 2017 10:32:46 GMT+0000 (UTC)

Trying to get through the codeā€¦
My curl gives back an Internal Server Error. Iā€™m quite confident that the lambda function is correct, because on the AWS web interface I can see the deployed code and can also see the changes in the DynamoDB that the API calls are making, so those are working now.
The same problem comes back later when making the API request from React.

curl https://y41nezzjc9.execute-api.us-west-2.amazonaws.com/prod/notes   -H "Authorization:(longlongauthcodehere)" -d "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}" -v
*   Trying 13.32.14.205...
* TCP_NODELAY set
* Connected to y41nezzjc9.execute-api.us-west-2.amazonaws.com (13.32.14.205) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.execute-api.us-west-2.amazonaws.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> POST /prod/notes HTTP/1.1
> Host: y41nezzjc9.execute-api.us-west-2.amazonaws.com
> User-Agent: curl/7.51.0
> Accept: */*
> Authorization:(longlongauthcodehere)
> Content-Length: 50
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 50 out of 50 bytes
< HTTP/1.1 502 Bad Gateway
< Content-Type: application/json
< Content-Length: 36
< Connection: keep-alive
< Date: Thu, 25 May 2017 10:25:55 GMT
< x-amzn-RequestId: 89464d15-4134-11e7-bb74-31c7498049ed
< X-Cache: Error from cloudfront
< Via: 1.1 e8b2113c9dc1cb4ee1d94126e9412be2.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: 7KoH1dZQkDaT5syNWnECefRYjem_22uMsmNDsL-yxUcozprOLpV_kQ==
<
* Curl_http_done: called premature == 0
* Connection #0 to host y41nezzjc9.execute-api.us-west-2.amazonaws.com left intact
{"message": "Internal server error"}

From @cwa821 on Sun May 28 2017 13:15:36 GMT+0000 (UTC)

The deploy is successful. But the curl test gives men the same {ā€œmessageā€: ā€œInternal server errorā€}. The CloudWatch log reports, ā€œUnable to import module ā€˜createā€™: Errorā€. When I test the function in Lambda, the execution fails with the message, ā€œerrorMessageā€: ā€œCannot find module ā€˜babel-runtime/regeneratorā€™ā€

Not sure what to do next.

From @jayair on Mon May 29 2017 10:25:44 GMT+0000 (UTC)

@cwa821 Thanks for finding the error. Let me take a look and see whatā€™s going on.

@frittate It sounds like you have the same issue as well.

From @jayair on Mon May 29 2017 12:45:56 GMT+0000 (UTC)

@frittate @cwa821 Iā€™m unable to replicate your issues. Can you post your package.json and .babelrc to see what you are using?

From @cwa821 on Mon May 29 2017 12:58:29 GMT+0000 (UTC)

Here you go.
Thanks,
Wes

package.json

{
  "name": "rfd-notes-app-api",
  "version": "1.0.0",
  "description": "",
  "main": "handler.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "aws-sdk": "^2.58.0",
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "glob": "^7.1.2",
    "serverless-webpack": "^1.0.0-rc.4",
    "webpack": "^2.6.1",
    "webpack-node-externals": "^1.6.0"
  },
  "dependencies": {
    "uuid": "^3.0.1"
  }
}

.babelrc

{
  "plugins": ["transform-runtime"],
  "presets": ["es2015", "stage-3"]
}

From @jayair on Mon May 29 2017 13:10:24 GMT+0000 (UTC)

@cwa821 Hmm you are missing babel-runtime. You might have missed this step in the tutorial - https://github.com/AnomalyInnovations/serverless-stack-com/blame/master/_chapters/add-support-for-es6-es7-javascript.md#L31

From @frittate on Mon May 29 2017 16:00:55 GMT+0000 (UTC)

@jayair Here are my files, I added the babel runtime dependency and deployed again, but curl still gives back a server error. Could this be a configuration in AWS services? I did update all CORS statements on the buckets and the deploy works (I can see the files in my AWS web interface no problem). Maybe itā€™s all a bit over my head ^^

From @cwa821 on Mon May 29 2017 20:01:16 GMT+0000 (UTC)

That fixed the problem. Just one more data point that multitasking is a myth.
Thanks for the help.
Wes

From @fwang on Mon May 29 2017 22:02:30 GMT+0000 (UTC)

@frittate I got a chance to try out your repository. Deploy was successful, and the curl fails with {"message": "Internal server error"}. I see the following error in CloudWatch:

Unable to import module 'list': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/list.js:122:19)
at __webpack_require__ (/var/task/list.js:20:30)
at Object.<anonymous> (/var/task/list.js:54:21)
at __webpack_require__ (/var/task/list.js:20:30)
at Object.defineProperty.value (/var/task/list.js:40:18)
at Object.<anonymous> (/var/task/list.js:43:10)

Do you see this? I was able to resolve this issue by updating the serverless.yml from

  ...
  "custom": null,
  "webpackIncludeModules": true,
  ...

to

  ...
  "custom": {
    "webpackIncludeModules": true
  },
  ...

From @frittate on Wed May 31 2017 15:47:54 GMT+0000 (UTC)

@jayair Hey, itā€™s awesome that you check all messages and look through the code. The curl was successful, but then the answer was an ā€˜unauthorizedā€™ message. I was able to fix this by going to the IAM policies and add a DynamoDBFullAccess policy in addition to the Administrator Access policy.
Now the apis are deployed! Very happy user :smiley:

Edit: spotting a mis-indented configuration is really awesome.

From @jayair on Wed May 31 2017 16:25:31 GMT+0000 (UTC)

@frittate No problem! Though @fwang did the hard work :wink:

PS: Star our repo && subscribe to our mailing list!

From @alexofob on Sun Jun 04 2017 17:23:27 GMT+0000 (UTC)

Hi there,

I faced an issue when the CLI output format was set to text. The response for the authentication was given in text and it was difficult to see what the IdToken is.

After running below command
export AWS_DEFAULT_OUTPUT=ā€œjsonā€

Format of the cli out put changed to JSON and it was easy to see the IdToken value.

Thanks.

From @jayair on Mon Jun 05 2017 00:46:28 GMT+0000 (UTC)

@alexofob Nice tip. Thanks for sharing!

From @alexung on Wed Jun 07 2017 23:49:50 GMT+0000 (UTC)

EDIT: Nevermind, I solved the issue. Simply redeployed the app and it seemed to work, huzzah!
Iā€™m getting {"message": "Internal server error"} on the curl command as well, although the deploy went well. Would genuinely appreciate assistance, not sure exactly whatā€™s going wrong.

serverless.yml

service: notes-app-api

plugins:
  - serverless-webpack

custom:
  webpackIncludeModules: true

provider:
  name: aws
  runtime: nodejs6.10
  stage: prod
  region: us-east-1

  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-east-1:*:*"

functions:
  create:
    handler: create.main
    events:
      - http:
          path: notes
          method: post
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:869126366080:userpool/us-east-1_xxxxxx
  get:
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:869126366080:userpool/us-east-1_xxxxxx

  list:
    handler: list.main
    events:
      - http:
          path: notes
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:869126366080:userpool/us-east-1_xxxxxx
  update:
    handler: update.main
    events:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:869126366080:userpool/us-east-1_xxxxxx
  delete:
    handler: delete.main
    events:
      - http:
          path: notes/{id}
          method: delete
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:869126366080:userpool/us-east-1_xxxxxx

package.json

{
  "name": "notes-app-api",
  "version": "1.0.0",
  "description": "",
  "main": "handler.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "aws-sdk": "^2.65.0",
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "babel-runtime": "^6.23.0",
    "glob": "^7.1.2",
    "serverless-webpack": "^1.0.0-rc.4",
    "webpack": "^2.6.1",
    "webpack-node-externals": "^1.6.0"
  },
  "dependencies": {
    "babel-runtime": "^6.23.0",
    "uuid": "^3.0.1"
  }
}

.babelrc

{
  "plugins": ["transform-runtime"],
  "presets": ["es2015", "stage-3"]
}

From @bennairn on Fri Jun 09 2017 16:25:32 GMT+0000 (UTC)

Looking for a bit of help here as Iā€™m stuck at the last step. Iā€™m able to deploy successfully, and all the earlier tests work fine but the curl fails with:

{ā€œmessageā€: ā€œInternal server errorā€}

Iā€™m running from Windows 10 if that matters. When I check the CloudWatch logs I find:

Unable to import module ā€˜createā€™: Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/var/task/create.js:131:19)
at webpack_require (/var/task/create.js:20:30)
at Object. (/var/task/create.js:54:21)
at webpack_require (/var/task/create.js:20:30)
at Object.defineProperty.value (/var/task/create.js:40:18)
at Object. (/var/task/create.js:43:10)

When I run

serverless deploy

Everything works fine, including creating all the functions.

Iā€™ve checked in S3 and a bucket was created in region US East (Ohio):

notes-app-api-prod-serverlessdeploymentbucket-xxxxxxxxxxxxx

Its worth noting that Iā€™m using US-east-2 not 1, and I think Iā€™m doing that consistently everywhere thatā€™s required (including Cognito). If I click through a few levels into that bucket I find a zip that contains the node_modules folder as well as all the API js files, plus handler.js and the package.json. So the ā€œcreateā€ file is definitely being uploaded.

Iā€™ve seen many similar comments (some here, some SO, some elsewhere) but havenā€™t been able to solve my problem. A lot of the similar posts I found talk about ensuring that the files (rather than the folder containing them) are zipped before uploading, but from what I can tell that isnā€™t the problem here. Iā€™m new to AWS and Serverless (hence the tutorial), but Iā€™m also new to javascript so perhaps that doesnā€™t help. My background is mostly in Python (and java a few years ago) but really in a totally different domain to this.

Iā€™ve also successfully removed the serverless stack and then deployed it again but that didnā€™t help either.
One of the problems Iā€™m having is that I donā€™t really know how (or more accurately where) to debug the problem myself. When I run curl, Iā€™m sending a POST request to ultimately trigger the create.js code and insert a new record in the database, but Iā€™m a bit lost on the mechanics. Where is the import module ā€˜createā€™ being called? If I could work this out then perhaps I could solve it myself. My code is below:

curl

curl https://uubnc4p8pf.execute-api.us-east-2.amazonaws.com/prod/notes -H "Authorization:eyJraWQiOiJoeXhMN0s5OEhsaXUzQ0JEaXpIM1wvR0prdkxMTkFMQlpGZlwvUWdiRXhKUnM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIzYjBlZDU3OC1hNDUwLTQ0OGItOTgxNS1kZGI3ZGNmNDk4MjciLCJhdWQiOiIxbGs4bmRwZW0wdXU3YTBqOW91N29kOWJuNCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE0OTcwMTkwMjYsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0yXzZEYjFKVVFkbiIsImNvZ25pdG86dXNlcm5hbWUiOiJhZG1pbkBleGFtcGxlLmNvbSIsImV4cCI6MTQ5NzAyMjYyNiwiaWF0IjoxNDk3MDE5MDI2LCJlbWFpbCI6ImFkbWluQGV4YW1wbGUuY29tIn0.Olh9ecWHphrxFwiCeMjOJFO2XC6cWKbLqk7hsGJSmueL95y4JCnLWdomTyLn4pb-0mv-Vd7h1vGSn5WR04EaryDhpq1ayXymah5JR8IU7PbvOYFsXuu0br5vxLO3ZRFzEfGCoCOmUC4Pe2Rs3VeBo7UWOpMvZYncUHHwqqt06IJJzolG9O5QMdT7cNgMOG_mzPCfpczdhmSXmrH7_6qXVLhx5cZMJv-a5MDUhOZPd6HSWPCl8zcxLxvQuBFeW152-mF6gfwzNYkHqfF4J3ZWZ0aW_cNp-f8Rkg_eOXmuEXRVKk4N_ZmiLVnBfPJbFrj6Fzpjsxm2pZ9DGuso1eC7iw" -d "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"
{"message": "Internal server error"}

serverless.yml

service: notes-app-api

plugins:
  - serverless-webpack

custom:
  webpackIncludeModules: true

provider:
  name: aws
  runtime: nodejs6.10
  stage: prod
  region: us-east-2

  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-east-2:*:*"

functions:
  create:
    handler: create.main
    events:
      - http:
          path: notes
          method: post
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:571611499065:userpool/us-east-2_xxxxxxxxx

  get:
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:571611499065:userpool/us-east-2_xxxxxxxxx

  list:
    handler: list.main
    events:
      - http:
          path: notes
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:571611499065:userpool/us-east-2_xxxxxxxxx

  update:
    handler: update.main
    events:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:571611499065:userpool/us-east-2_xxxxxxxxx

  delete:
    handler: delete.main
    events:
      - http:
          path: notes/{id}
          method: delete
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:571611499065:userpool/us-east-2_xxxxxxxxx

package.js

  "name": "notes-app-api",
  "version": "1.0.0",
  "main": "handler.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "aws-sdk": "^2.65.0",
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "glob": "^7.1.2",
    "serverless-webpack": "^1.0.0-rc.4",
    "webpack": "^2.6.1",
    "webpack-node-externals": "^1.6.0"
  },
  "dependencies": {
    "uuid": "^3.0.1"
  },
  "description": ""
}

From @frittate on Fri Jun 09 2017 22:13:54 GMT+0000 (UTC)

Try to copy (fork) my serverless.yml (itā€™s formatted in json-style) which makes it easier to read imho. If the problem persists, do the same with create.js. Also, your package.js is missing babel-runtime from the dependencies, so add this line: "babel-runtime": "^6.23.0",

From @bennairn on Sat Jun 10 2017 04:35:30 GMT+0000 (UTC)

Adding "babel-runtime": "^6.23.0" to the package.json dependencies fixed it. Thanks so much @frittate !!