Deploy the APIs


#21

From @ericorruption on Fri Apr 21 2017 09:53:44 GMT+0000 (UTC)

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?


#22

From @ericorruption on Fri Apr 21 2017 11:50:27 GMT+0000 (UTC)

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

#23

From @riogaj89 on Mon Apr 24 2017 20:08:40 GMT+0000 (UTC)

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

Could use any help from here?


#24

From @jayair on Mon Apr 24 2017 20:22:30 GMT+0000 (UTC)

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


#25

From @riogaj89 on Mon Apr 24 2017 20:23:46 GMT+0000 (UTC)

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

#26

From @jayair on Mon Apr 24 2017 20:54:17 GMT+0000 (UTC)

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?


#27

From @riogaj89 on Mon Apr 24 2017 20:58:38 GMT+0000 (UTC)

Yes it did work for me just fine.


#28

From @jayair on Tue Apr 25 2017 17:03:56 GMT+0000 (UTC)

@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.


#29

From @riogaj89 on Tue Apr 25 2017 19:23:06 GMT+0000 (UTC)

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


#30

From @fwang on Tue Apr 25 2017 22:00:25 GMT+0000 (UTC)

@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)?


#31

From @riogaj89 on Wed Apr 26 2017 10:37:09 GMT+0000 (UTC)

Ah… Yes that was right. Managed to resolve the issue. Thank you very much fwang and jayair for the help!


#32

From @ShaklinSyed on Wed May 03 2017 10:29:44 GMT+0000 (UTC)

I was getting the status:fasle response, so consoled the error and i got the error response as follows {"status":{"message":"One or more parameter values were invalid: Missing the key userid in the item","code":"ValidationException","time":"2017-05-03T10:24:54.551Z","requestId":"5GA3CQH984DC39OPREJIF8MVORVV4KQNSO5AEMVJF66Q9ASUAAJG","statusCode":400,"retryable":false,"retryDelay":24.05818543697169}}


#33

From @fwang on Wed May 03 2017 19:21:48 GMT+0000 (UTC)

@ShaklinSyed At which step did you run into this error?

It sounds look like there is a mismatch between the key name defined in DynamoDB table and that used in the Lambda code. Double check the key name is consistent. (ie. key names in the tutorial are in camel case - userId with capital ‘I’)


#34

From @ShaklinSyed on Thu May 04 2017 05:15:04 GMT+0000 (UTC)

@fwang Fixed it. works now. Thanks.


#35

From @eloquentbit on Sat May 06 2017 07:36:53 GMT+0000 (UTC)

Hi, great guide! I can’t deploy on AWS:

Serverless: Bundling with Webpack...
Time: 761ms
            Asset     Size  Chunks             Chunk Names
        create.js  6.35 kB       0  [emitted]  create
        delete.js  5.46 kB       1  [emitted]  delete
           get.js  5.62 kB       2  [emitted]  get
       handler.js  2.28 kB       3  [emitted]  handler
          list.js  5.83 kB       4  [emitted]  list
        update.js   6.2 kB       5  [emitted]  update
webpack.config.js  3.19 kB       6  [emitted]  webpack.config
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...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - scratch-app-api-prod
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - 1UnderscorevTBvqUZ8BLambdaPermissionApiGateway
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DeleteLogGroup
CloudFormation - CREATE_FAILED - AWS::Lambda::Permission - 1UnderscorevTBvqUZ8BLambdaPermissionApiGateway
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
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_FAILED - 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 - scratch-app-api-prod
CloudFormation - UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - scratch-app-api-prod
CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - DELETE_COMPLETE - AWS::Lambda::Permission - 1UnderscorevTBvqUZ8BLambdaPermissionApiGateway
CloudFormation - DELETE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - DeleteLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - CreateLogGroup
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - DeleteLogGroup
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - GetLogGroup
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - ListLogGroup
CloudFormation - DELETE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - UpdateLogGroup
CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - scratch-app-api-prod
Serverless: Deployment failed!

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

     An error occurred while provisioning your stack: 1UnderscorevTBvqUZ8BLambdaPermissionApiGateway
     - 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:       7.10.0
     Serverless Version: 1.12.1

This is my serverless.yml file:

service: scratch-app-api

# Use serverless-webpack plugin to transpile ES6/ES7
plugins:
  - serverless-webpack

# Enable auto-packing of external modules
custom:
  webpackIncludeModules: true

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

  # '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:eu-west-1:*:*"

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:eu-west-1:277846935261:userpool/eu-west-1_vTBvqUZ8B

  get:
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer:
            arn: aws:cognito-idp:eu-west-1:277846935261:userpool/eu-west-1_vTBvqUZ8B

  list:
    handler: list.main
    events:
      - http:
          path: notes
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:277846935261:userpool/eu-west-1_vTBvqUZ8B

  update:
    handler: update.main
    events:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:277846935261:userpool/eu-west-1_vTBvqUZ8B

  delete:
    handler: delete.main
    events:
      - http:
          path: notes/{id}
          method: delete
          cors: true,
          authorizer:
            arn: arn:aws:cognito-idp:eu-west-1:277846935261:userpool/eu-west-1_vTBvqUZ8B

#36

From @fwang on Sun May 07 2017 13:31:00 GMT+0000 (UTC)

Is the comma ‘,’ at the end of the last cors:true in your serverless.yml?


#37

From @eloquentbit on Mon May 08 2017 10:31:52 GMT+0000 (UTC)

Thanks @fwang, I fixed the code but unfortunately the problem persists


#38

From @alpiepho on Mon May 08 2017 20:30:11 GMT+0000 (UTC)

Most of the example files refer to “us-east-1”. I happen to be on “us-west-2”. I cut/pasted the original serverless.yml files somewhere thru the tutorial and didn’t catch the differences. After changing it to “us-west-2” in the iamRoleStatements:Resources section, my test of the deployed system succeeds. (So I am inferring that was my problem).

My suggestion is to update the tutorials to illustrate the need to change these fields. Please don’t change it to something like USE_YOUR_REGION. The actual region string format is useful. Just need to know that they need to change.

Thanks Jay for the quick Chat response.


#39

From @jayair on Wed May 10 2017 02:04:17 GMT+0000 (UTC)

@alpiepho yeah the region thing can be a gotcha for people. I’ll try and find the places that need the heads up.


#40

From @mitchallen on Thu May 11 2017 20:22:56 GMT+0000 (UTC)

$ aws --version
aws-cli/1.10.24 Python/2.7.10 Darwin/15.6.0 botocore/1.4.15

When I try to run the aws cognito-idp admin-initiate-auth command I get back an error with a list of commands that don’t include admin-initiate-auth.

If I run:

$ aws cognito-idp help

It isn’t included as a listed option:

   o add-custom-attributes
   o admin-confirm-sign-up
   o admin-delete-user
   o admin-delete-user-attributes
   o admin-disable-user
   o admin-enable-user
   o admin-get-user
   o admin-reset-user-password
   o admin-set-user-settings
   o admin-update-user-attributes