0
votes

I have built a simple Node.JS application that consists of a single API endpoint. Deployment works and I can all the API endpoint as expected. However the handler function also runs on deployment of the code, which is problematic for me as handler function posts a tweet to twitter, and I don't want it to tweet every time I deploy a code update. I haven't been able to find anyone online reporting a similar problem, but I'm sure this would not be expected functionality.

This is my serverless.yml file (I created originally from the GitLab Node.JS serverless template here https://gitlab.com/gitlab-org/project-templates/serverless-framework/):

service: my-project
provider:
  name: aws
  region: ${env:AWS_REGION}
  runtime: nodejs10.x

plugins:
  - serverless-offline
  - serverless-jest-plugin
  - serverless-stack-output # Allows us to output endpoint url to json file

functions:
  post:
    handler: main.main
    events:
      - http:
          path: post
          method: post

custom:
  output:
    handler: main.main
    file: stack.json
1
Strange! What is your deployment script? Does it also invoke the function right after the deployment? - Reaz Murshed
I haven't changed any of the deployment process from the linked template, so that should hopefully give some greater detail. But essentially my deployment just amounts to serverless deploy --stage production --verbose - Raiden616
(I got rid of all stages from the .gitlab-ci.yml except for the production stage, so there's no post-deploy checks or anything running) - Raiden616

1 Answers

0
votes

I believe the problem in your case is the fact that the handler you have for serverless-stack-output plugin is the same as for your function. That plugin explicitly calls the handler (https://github.com/sbstjn/serverless-stack-output#handler) which executes your function. If you will drop use of the plugin or just configure a different handler for it the problem should disappear