Deploy the APIs


#41

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

#42

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.


#43

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.


#44

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"}

#45

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.


#46

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.


#47

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?


#48

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"]
}

#49

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


#50

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 ^^


#51

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


#52

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
  },
  ...

#53

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.


#54

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!


#55

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.


#56

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

@alexofob Nice tip. Thanks for sharing!


#57

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"]
}

#58

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": ""
}

#59

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",


#60

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 !!