New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments: Deploy the APIs #28

Closed
jayair opened this Issue Apr 10, 2017 · 122 comments

Comments

Projects
None yet
@jayair
Copy link
Member

jayair commented Apr 10, 2017

@jayair jayair added the Discussion label Apr 10, 2017

@congliu01

This comment has been minimized.

Copy link

congliu01 commented Apr 12, 2017

I got {"message":"Unauthorized"} error.

I changed the OUR_COGNITO_USER_POOL_ID and YOUR_COGNITO_APP_CLIENT_ID and got the IdToken. I replaced the IdToken with mine. I also changed the endpoint to my own API gateway endpoint.

Any ideas?

@fwang

This comment has been minimized.

Copy link
Member

fwang commented Apr 12, 2017

Could you post the functions section in your serverless.yml of the endpoint you are trying to invoke?

@JUSTPERFECT

This comment has been minimized.

Copy link
Contributor

JUSTPERFECT commented Apr 12, 2017

@congliu01

This comment has been minimized.

Copy link

congliu01 commented Apr 13, 2017

Below is the functions section in my serverless.yml. I doubled checked my keys and I don't think I made any copy/paste mistakes.

BTW, I can use the UI to create/update notes.

functions:
  # Defines an HTTP API endpoint that calls the main function in create.js
  # - path: url path is /notes
  # - method: POST request
  # - cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
  #     domain api call
  # - authorizer: authenticate the api via Cognito User Pool. Update the 'arn'
  #     with your own User Pool ARN
  create:
    handler: create.main
    events:
      - http:
          path: notes
          method: post
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:099521359077:userpool/us-east-1_CuWTSHcJb

  get:
      # Defines an HTTP API endpoint that calls the main function in get.js
      # - path: url path is /notes/{id}
      # - method: GET request
      handler: get.main
      events:
        - http:
            path: notes/{id}
            method: get
            cors: true
            authorizer:
              arn: arn:aws:cognito-idp:us-east-1:099521359077:userpool/us-east-1_CuWTSHcJb

  list:
    # Defines an HTTP API endpoint that calls the main function in list.js
    # - path: url path is /notes
    # - method: GET request
    handler: list.main
    events:
      - http:
          path: notes
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:099521359077:userpool/us-east-1_CuWTSHcJb

  update:
    # Defines an HTTP API endpoint that calls the main function in update.js
    # - path: url path is /notes/{id}
    # - method: PUT request
    handler: update.main
    events:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:099521359077:userpool/us-east-1_CuWTSHcJb

  delete:
    # Defines an HTTP API endpoint that calls the main function in delete.js
    # - path: url path is /notes/{id}
    # - method: DELETE request
    handler: delete.main
    events:
      - http:
          path: notes/{id}
          method: delete
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-1:099521359077:userpool/us-east-1_CuWTSHcJb
@fwang

This comment has been minimized.

Copy link
Member

fwang commented Apr 13, 2017

The React app (UI) calls the APIs the exact same way as the bash curl. If you inspect the HTTP request in the browser, you should see the IdToken used in the Authorization header and the JSON request body. Try curling with them.

@dmurraykauai

This comment has been minimized.

Copy link

dmurraykauai commented Apr 18, 2017

After running 'serverless deploy -v' I received the response below. (Unable to parse HTTP response content.) All API's passed their tests and now I'm suddenly stuck on this error. Any ideas?

david@DESKTOP-U1APQB8 MINGW64 /d/Projects/Serverless/notes-app-api
$ serverless deploy -v
Serverless: Bundling with Webpack...
Time: 3501ms
     Asset     Size  Chunks             Chunk Names
 create.js   5.8 kB       0  [emitted]  create
 delete.js  5.66 kB       1  [emitted]  delete
    get.js  5.88 kB       2  [emitted]  get
handler.js  2.28 kB       3  [emitted]  handler
   list.js   5.9 kB       4  [emitted]  list
 update.js   6.2 kB       5  [emitted]  update
Serverless: Packing external modules: babel-runtime@^6.23.0, uuid@^3.0.1
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading function .zip files to S3...
Serverless: Uploading service .zip file to S3 (1.03 MB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - notes-app-api-prod
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - 2UnderscoreJLN0gaaY4LambdaPermissionApiGateway
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - CREATE_FAILED - AWS::Lambda::Permission - 2UnderscoreJLN0gaaY4LambdaPermissionApiGateway
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DeleteLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - CREATE_FAILED - AWS::Logs::LogGroup - DeleteLogGroup
CloudFormation - CREATE_FAILED - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - UPDATE_ROLLBACK_IN_PROGRESS - AWS::CloudFormation::Stack - notes-app-api-prod
CloudFormation - UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - notes-app-api-prod
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - DELETE_COMPLETE - AWS::Lambda::Permission - 2UnderscoreJLN0gaaY4LambdaPermissionApiGateway
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - DeleteLogGroup
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - DELETE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - notes-app-api-prod
Serverless: Deployment failed!

  Serverless Error ---------------------------------------

     An error occurred while provisioning your stack: 2UnderscoreJLN0gaaY4LambdaPermissionApiGateway
     - 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:                 win32
     Node Version:       7.2.0
     Serverless Version: 1.11.0
@PatrykTies

This comment has been minimized.

Copy link

PatrykTies commented Apr 18, 2017

I did receive the same Error as above once deployed.
On Stack they saying we must provide statusCode along with response...as we did in tutorial..but perhaps we must add it on API Gateway level also...i dont know at the moment...trying to fix it
http://stackoverflow.com/questions/37137601/unable-to-parse-http-response-content-when-creating-apigatewayresource

@fwang

This comment has been minimized.

Copy link
Member

fwang commented Apr 18, 2017

@dmurraykauai @PatrykTies A couple of things could cause the "Unable to parse HTTP response content" error.

Let's do a quick sanity check. Could you share your serverless.yml file?

@PatrykTies

This comment has been minimized.

Copy link

PatrykTies commented Apr 18, 2017

service: notes-app 

plugins:
  - serverless-webpack

custom:
  webpackIncludeModules: true


provider:
  name: aws
  runtime: nodejs6.10
  stage: prod
  region: eu-west-1


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

functions:

  create:
    handler: create.main
    events:
      - http:
          path: notes
          method: post
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:421235352293:userpool/eu-west-1_xxxxxxx
  get:
    
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:421235352293:userpool/eu-west-1_xxxxxxx
  list:
    
    handler: list.main
    events:
      - http:
          path: notes
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:421235352293:userpool/eu-west-1_xxxxxxxx
  update:
  
    handler: update.main
    events:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:421235352293:userpool/eu-west-1_xxxxxxxx
  delete:
  
    handler: delete.main
    events:
      - http:
          path: notes/{id}
          method: delete
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:421235352293:userpool/eu-west-1_xxxxxxxx
@dmurraykauai

This comment has been minimized.

Copy link

dmurraykauai commented Apr 18, 2017

Pasting the code in between the back ticks doesn't render too good. I've attached serverless.yml.txt to this post. Thanks for the assist!


service: notes-app-api

plugins:
  - serverless-webpack

custom:
  webpackIncludeModules: true
[serverless.yml.txt](https://github.com/AnomalyInnovations/serverless-stack-com/files/930746/serverless.yml.txt)

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

  # 'iamRoleStatement' defines the permission policy for the Lambda function.
  # In this case Lambda functions are granted with permissions to access DynamoDB.
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-west-2:*:*"

functions:
  # Defines an HTTP API endpoint that calls the main function in create.js
  # - path: url path is /notes
  # - method: POST request
  # - cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
  #     domain api call
  # - authorizer: authenticate the api via Cognito User Pool. Update the 'arn'
  #     with your own User Pool ARN
  create:
    handler: create.main
    events:
      - http:
          path: notes
          method: post
          cors: true
          authorizer:
            arn: aws:cognito-idp:us-west-2:939466294100:userpool/us-west-2_JLN0gaaY4
  get:
      # Defines an HTTP API endpoint that calls the main function in get.js
      # - path: url path is /notes/{id}
      # - method: GET request
      handler: get.main
      events:
        - http:
            path: notes/{id}
            method: get
            cors: true
            authorizer:
              arn: aws:cognito-idp:us-west-2:939466294100:userpool/us-west-2_JLN0gaaY4
  list:
      # Defines an HTTP API endpoint that calls the main function in list.js
      # - path: url path is /notes
      # - method: GET request
      handler: list.main
      events:
        - http:
            path: notes
            method: get
            cors: true
            authorizer:
              arn: aws:cognito-idp:us-west-2:939466294100:userpool/us-west-2_JLN0gaaY4
  update:
      # Defines an HTTP API endpoint that calls the main function in update.js
      # - path: url path is /notes/{id}
      # - method: PUT request
      handler: update.main
      events:
        - http:
            path: notes/{id}
            method: put
            cors: true
            authorizer:
              arn: aws:cognito-idp:us-west-2:939466294100:userpool/us-west-2_JLN0gaaY4
  delete:
      # Defines an HTTP API endpoint that calls the main function in delete.js
      # - path: url path is /notes/{id}
      # - method: DELETE request
      handler: delete.main
      events:
        - http:
            path: notes/{id}
            method: delete
            cors: true
            authorizer:
              arn: aws:cognito-idp:us-west-2:939466294100:userpool/us-west-2_JLN0gaaY4
@fwang

This comment has been minimized.

Copy link
Member

fwang commented Apr 18, 2017

@dmurraykauai the authorizer arn should start with arn: and the authorizer line should look something like

authorizer:
  arn: arn:aws:cognito-idp:us-east-1:xxxxxxxxxxxx:userpool/us-east-1_XXXXXxxxx
@dmurraykauai

This comment has been minimized.

Copy link

dmurraykauai commented Apr 18, 2017

ok, that was a bit confusing... arn: arn:aws: .... thought I tried w/ the double arn: already but let me try again. Thank you!

@dmurraykauai

This comment has been minimized.

Copy link

dmurraykauai commented Apr 18, 2017

Beautiful, works fine now. Thanks again @fwang ! Much appreciated.

@fwang

This comment has been minimized.

Copy link
Member

fwang commented Apr 18, 2017

@PatrykTies hmmm.. it looks fine. Could you double check a few things:

  • both Identity pool and User pool are created inside eu-west-1 region;
  • userpool id is usually 9 characters long, ensure the authorizer arn is not missing any character at the end arn: arn:aws:cognito-idp:eu-west-1:421235352293:userpool/eu-west-1_xxxxxxx
@jtrollia

This comment has been minimized.

Copy link

jtrollia commented Apr 19, 2017

Hi,

Thanks for your super guide

I'm struggling with cognito and serverless, I'm having the same problem as @dmurraykauai I guess.

I'm declaring my function as follows:

searchname:
  handler: handler.searchname
  events:
    - http:
        path: search/name/{value}
        method: get
        private: true
        cors: true
        authorizer:
          arn: ${self:custom.poolArn}
    - stream: ${self:custom.dynamoArn} 

All my services are running on ap-northeast-2 and my poolArn variable is equal to arn:aws:cognito-idp:ap-northeast-2:XXXXXXXXXXXX:userpool/ap-northeast-2_xxxxxxx.

When I try to deploy my service, I get the following logs:

CloudFormation - CREATE_FAILED - AWS::Lambda::Permission - 2UnderscorexxxxxxxLambdaPermissionApiGateway
CloudFormation - CREATE_FAILED - AWS::ApiGateway::Authorizer - 2UnderscorexxxxxxxApiGatewayAuthorizer

Depending on AWS settings (e.g., switching Authorization to AWS_IAM), the process ends with one of these error messages:

- Unable to parse HTTP response content.
- Invalid lambda function.

Everything works fine if I comment the authorizer lines.

I've set manually IAM permissions for lambda:

{
    "Action": [
        "lambda:*"
    ],
    "Resource": "*",
    "Effect": "Allow"
},

I also had a look at many related issues, I saw you answered one on serverless forums. However, their official doc is really light regarding cognito as an authorizer... Note that I'm just using Cognito user pool, without Cognito identity pool.

How did you get your example working? Are there extra settings to deal with on the dashboard?

Thanks


Edit 1: I found a solution that solves the following alert:

CloudFormation - CREATE_FAILED - AWS::ApiGateway::Authorizer - 2UnderscorexxxxxxxApiGatewayAuthorizer
@jtrollia

This comment has been minimized.

Copy link

jtrollia commented Apr 20, 2017

Yo,

Never mind, I was using Serverless 1.4.0, I had a look at changelogs and figured out I should update to the latest version.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 20, 2017

@Malivuk thanks for reporting back. It'll help anybody else that might run into this.

@PatrykTies

This comment has been minimized.

Copy link

PatrykTies commented Apr 20, 2017

Yes I can confirm, my issue above was also caused by using 1.4 , now once updated to 1.11 all works fine.
Cheers.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 20, 2017

@Malivuk couldn't have timed your response any more perfectly 😉

Or maybe @PatrykTies had it figured out before he saw your message.

@ericorruption

This comment has been minimized.

Copy link

ericorruption commented Apr 21, 2017

Hello,

I couldn't get to the actual deploying. I followed the tutorial by the book. Got this error:

Serverless: Bundling with Webpack...
Time: 771ms
    Asset     Size  Chunks             Chunk Names
create.js  5.75 kB       0  [emitted]  create
delete.js  5.41 kB       1  [emitted]  delete
   get.js   5.5 kB       2  [emitted]  get
  list.js  5.44 kB       3  [emitted]  list
update.js  5.78 kB       4  [emitted]  update
Serverless: Packing external modules: babel-runtime@^6.23.0, uuid@^3.0.1
Serverless: Packaging service...

  Stack Trace --------------------------------------------

TypeError: Cannot read property 'path' of null
    at AwsCompileApigEvents.getHttpPath (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/compile/events/apiGateway/lib/validate.js:145:20)
    at _.forEach (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/compile/events/apiGateway/lib/validate.js:46:28)
    at arrayEach (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:9344:14)
    at _.forEach (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/compile/events/apiGateway/lib/validate.js:42:9)
    at /usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:4970:15
    at baseForOwn (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:3020:24)
    at /usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:4939:18
    at Function.forEach (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:9344:14)
    at AwsCompileApigEvents.validate (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/compile/events/apiGateway/lib/validate.js:41:7)
    at Object.deploy:compileEvents [as fn] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/compile/events/apiGateway/index.js:42:31)
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:210:55)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:210:22)
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:225:17)
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:97:31)
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless:23:50)

  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       7.9.0
     Serverless Version: 1.11.0

I tried using older versions of aws-sdk and serverless and got the same error. I compared my codebase to the one of the examples and it's exactly the same.

Anyone been through this?

@ericorruption

This comment has been minimized.

Copy link

ericorruption commented Apr 21, 2017

Solved it. Plain stupidity: i had path one level shallower on serverless.yml

  list:
    handler: list.main
    events:
      - http:
        path: notes

should be:

  list:
    handler: list.main
    events:
      - http:
          path: notes
@riogaj89

This comment has been minimized.

Copy link

riogaj89 commented Apr 24, 2017

I am currently experiencing this as a response {"status":false}

Could use any help from here?

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 24, 2017

@riogaj89 can you show me which command is giving you that response?

@riogaj89

This comment has been minimized.

Copy link

riogaj89 commented Apr 24, 2017

Sure.

curl https://5456icd6za.execute-api.us-east-1.amazonaws.com/dev/notes \
-H "Authorization:eyJraWQiOiJPNXVpQTJQQVBEaTYxUlBqc2huN3hLZGN5ZlE1SndiellWR0VkcURBQXBZPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2OTFlMWEzOC01NWIzLTRmMTItYWQ0YS1jYzU2ZDViZTc4MjUiLCJhdWQiOiIzM2Y0aWV1aWF2amZ0MWZucms0NWowZWNnOCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE0OTMwNjQzNjksImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTEuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0xX2ZxUXZGTnJkWCIsImNvZ25pdG86dXNlcm5hbWUiOiJyaW9nYWpAZ21haWwuY29tIiwiZXhwIjoxNDkzMDY3OTY5LCJpYXQiOjE0OTMwNjQzNjksImVtYWlsIjoicmlvZ2FqQGdtYWlsLmNvbSJ9.a_P1IrjgT4iKUK7CIK1l2az3nQQb4c7uRfITYz8icdwzCtbCTk-nfuk_54aMmL0s2IoJ-UwEHsAEyCz_abxwF2pi7HW6pZ5GGktWAOH8U8-3jedwReyQOIBxYvW0YPadAUuPsLNtTlXNIM2TMFKIiqig7IHrlPW2CCqSt7y-760p4egIF8IIYM5EFveLYd4GSBuecWhDr2atFf9Dvn6ixjPHVfFQ9aATt4goPEtihwrgXH_7poi7N2QmGrP0o4T3Wgjl98c7oSmjxk7qBu2ivx7ihE_GYFgOFIxW4RGt4cGLwBabvdRPvBbXCrVB0lf8eBNIRgfRca7XOxbIAFqbYQ" \
-d "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"
@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 24, 2017

Just to double-check, did the serverless webpack invoke --function create --path event.json command in the Create Note chapter - http://serverless-stack.com/chapters/add-a-create-note-api.html work for you?

@riogaj89

This comment has been minimized.

Copy link

riogaj89 commented Apr 24, 2017

Yes it did work for me just fine.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 25, 2017

@riogaj89 the status: false is generated by our code, so we should be able to debug this. Above this line - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/create.js#L23, can you try to console.log the error? Make sure you serverless deploy after changing it.

To see the output for this, head over to your AWS Console > CloudWatch > Logs > The Lambda we created > The most recent log stream. And see what it shows there. If you are having problems finding where to look, let me know.

@riogaj89

This comment has been minimized.

Copy link

riogaj89 commented Apr 25, 2017

It says: AccessDeniedException: User: arn:aws:sts::435241600237:assumed-role/gajen-notes-app-dev-us-east-1-lambdaRole/gajen-notes-app-dev-create is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-east-1:435241600237:table/notes

@fwang

This comment has been minimized.

Copy link
Member

fwang commented Apr 25, 2017

@riogaj89 looks like the Lambda function does not have permission to write to the DynamoDB table. May I take a look at your serverless.yml file (iamRoleStatements section)?

@jayair

This comment has been minimized.

@akolybelnikov

This comment has been minimized.

Copy link

akolybelnikov commented Oct 23, 2017

I have resolved this issue by going over to Windows: I have tried to deploy on WSL first.

@stefangiapantzakis

This comment has been minimized.

Copy link

stefangiapantzakis commented Nov 11, 2017

iamRoleStatements should be an array of objects, where each object has Effect, Action, Resource fields. Specifically, statement 0 is missing the following properties: Resource

Error being thrown when calling serverless deploy

Below is my serverless.yml
https://gist.github.com/stefaanja/5136a9d08f3aae36c37eb39db4cb9768

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Nov 11, 2017

@stefaanja In this line here - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/serverless.yml#L22; notice that it is dynamodb:DescribeTable and not dynamodb: DescribeTable. There shouldn't be a space in between.

@spiraltrip

This comment has been minimized.

Copy link

spiraltrip commented Dec 21, 2017

When I want to redeploy my functions using serverless deploy, I get this error:

ENOTEMPTY: directory not empty, rmdir 'C:\xxxxxxx\notes-app-api\.webpack\dependencies\node_modules\.bin'

I have tried to deploy a single function, but was given this error:

The function "update" you want to update is not yet deployed. Please run "serverless deploy" to deploy your service. After that you can redeploy your services functions with the "serverless deploy function" command.

All functions are working fine through API gateway, except update (when saving changes to an existing note), which I am trying to troubleshoot by redeploying all functions again.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Dec 21, 2017

@spiraltrip So it works fine when you deployed the first time? But not when you make a change and deploy again?

@akolybelnikov

This comment has been minimized.

Copy link

akolybelnikov commented Dec 21, 2017

I have encountered the same issue twice! With various error messages. I have re-deployed the functions without any changes with a new service name, i.e. completely fresh Lambda functions, and deleted the previous ones. After third “new” deployment all sebsequent redeployments started to work seamlessly. But it is true, that you cannot just create a completely new function and deploy it separately. In this case yoo have to redeploy all again.

@spiraltrip

This comment has been minimized.

Copy link

spiraltrip commented Dec 22, 2017

Hi @jayair it worked fine deploying it for the first time. I intentionally left Update API out when I first deployed them. Then I tried to deploy Update API much later as a standalone function, which failed. So I tried to deploy them all together but got this ENOTEMPTY error instead.

@akolybelnikov , I have re-deployed everything from scratch again and it worked this time. I did it by starting all over with serverless -g install and creating the templates all over again. But it was a copy and paste of my previous codes. I initialised nodejs with package.json and reinstallation of all node modules / plugins.

@ivyliolia

This comment has been minimized.

Copy link

ivyliolia commented Dec 27, 2017

Hello @jayair I've encountered the "Cannot find module 'babel-runtime/regenerator'" and I saw the same error message that some people above met:

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.<anonymous> (/var/task/create.js:76:18)
at __webpack_require__ (/var/task/create.js:20:30)
at Object.<anonymous> (/var/task/create.js:166:20)
at __webpack_require__ (/var/task/create.js:20:30)
at /var/task/create.js:63:18
at Object.<anonymous> (/var/task/create.js:66:10)

The deploy is ok but when trying to test using apig, I keep getting this error. I've tried to use serverless 1.17 and sls remove then sls deploy too. Would you please help on this?

npm: 5.6.0
sls: 1.17.0
repo: https://github.com/ivyliolia/notes-app-api

Many thanks~~

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Dec 27, 2017

@ivyliolia Ah there is a typo on this line - https://github.com/ivyliolia/notes-app-api/blob/master/serverless.yml#L20

Change - webpackIncludeModules: true to webpackIncludeModules: true.

@walshe

This comment has been minimized.

Copy link

walshe commented Jan 20, 2018

each time I use serverless to deploy my service it seems to give a new prefix to the api gateways.. thus screwing up oauth callback urls I have configured elsewhere

e.g GET - https://c1d3sunyxx.execute-api.us-east-1.amazonaws.com/prod/bc/oauth

after a new deploy it might be something like

https://yyyyyyyyy.execute-api.us-east-1.amazonaws.com/prod/bc/oauth

is there a simple way to get around this ?

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jan 23, 2018

@walshe These remain constant as long as the service name remains the same in your serverless.yml - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/serverless.yml#L1 and as long as you don't do a serverless remove in between.

@walshe

This comment has been minimized.

Copy link

walshe commented Jan 23, 2018

@jayair ah, thanks :)

@shawnnolanjr

This comment has been minimized.

Copy link

shawnnolanjr commented Feb 3, 2018

Just a heads up, I was also getting "Internal Server Error", and after checking the logs saw "Unable to import module 'create'". Going back through the code and files noticed my package.json file got wiped out some how. Put that back and all on track now.

Moral of the story, CloudWatch logs is where its at!

@ivanms1

This comment has been minimized.

Copy link

ivanms1 commented Feb 4, 2018

Hello everyone, my deploy was successful but I got three endpoints instead of 5 like in the example code.
I got the first
POST ...
GET ....
GET ....
but no PUT and DELETE, is this an issue? how can I go about it?
I got all the functions by the way.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Feb 5, 2018

@ivanms1 Can I see your serverless.yml?

@ivanms1

This comment has been minimized.

Copy link

ivanms1 commented Feb 7, 2018

@jayair sure, here it is.

service: notes-app-api # NOTE: update this with your service name

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:State-change
        - 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: aws_iam

  get:
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer: aws_iam

  list:
    handler: list.main
    events:
      - http:
          path: notes
          method: get
          cors: true
          authorizer: aws_iam

  update:
    handler: update.main
    event:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer: aws_iam

  delete:
    handler: delete.main
    event:
      - http:
          path: notes/{id}
          method: delete
          cors: true
          authorizer: aws_iam
@jayair

This comment has been minimized.

Copy link
Member

jayair commented Feb 9, 2018

@ivanms1 Your PUT and DELETE handlers use the keyword event instead of events.

@ivanms1

This comment has been minimized.

Copy link

ivanms1 commented Feb 10, 2018

@jayair oh silly me, thank you so much!

@mjbf0748

This comment has been minimized.

Copy link

mjbf0748 commented Mar 26, 2018

Hi,

I am developing a web application using this tutorial. I was wondering if anyone could help/give advice on how to approach this issue. I am trying to use 2 different dynamodb tables. So I want the users to access things from both. Is there anyway to set up the apis to make calls to both tables?

Thank you

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Mar 26, 2018

@mjbf0748 Answered you in the other thread.

@daenamkim

This comment has been minimized.

Copy link
Contributor

daenamkim commented Apr 10, 2018

@jayair

Hi,

I want to know why dynamodb access policy wasn't applied into lambda's role after deployment.

Here I did.

  1. I followed all procedures of serverless stack to build backed APIs and added role in serverless.yml as well and deployed it.
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:*:*"
  1. I ran apig-test and an error responded.
{ status: 500,
  statusText: 'Internal Server Error',
  data: { status: false } }

And in the CouldWatch

AccessDeniedException: User: arn:aws:sts:: ... lambdaRole ... create is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-east-1: ... :table/notes
  1. So I checked out lambda's role but there was no dynamodb access policy. I don't know why.
    I added a policy setting.
{
    "Effect": "Allow",
    "Action": [
      "dynamodb:DescribeTable",
      "dynamodb:Query",
      "dynamodb:Scan",
      "dynamodb:GetItem",
      "dynamodb:PutItem",
      "dynamodb:UpdateItem",
      "dynamodb:DeleteItem"
    ],
    "Resource": "arn:aws:dynamodb:us-east-1:*:*"
}

It worked!

Thank you.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 10, 2018

@daenamkim Can you check to make sure the iamRoleStatements section is formatted correctly? Compare it to the file in the tutorial - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/serverless.yml. That can usually cause the problem.

@daenamkim

This comment has been minimized.

Copy link
Contributor

daenamkim commented Apr 11, 2018

@jayair

It was an indent issue.

Thank you so much!!!!

@jayair jayair closed this May 9, 2018

@jayair jayair reopened this May 9, 2018

@jayair

This comment has been minimized.

Copy link
Member

jayair commented May 9, 2018

@jayair jayair closed this May 9, 2018

@TheKippo

This comment has been minimized.

Copy link

TheKippo commented Oct 29, 2018

I am getting a Network Error after creating a note. I am stuck here and can't progress until this error is solved. Please help.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Oct 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment