31

I'm trying to deploy an AWS API with serverless.com

When I do:

sls --stage=dev --aws-profile=myprofile deploy --force

I get the following warning:

Configuration warning at 'functions.app.events[0]': unsupported function event

My serverless.yml contains the section:

functions:
  app:
    handler: src/index.handler
    memorySize: 3008
    events:
      - httpApi:
        method: '*'
        path: '*'
        authorizer:
          name: serviceAuthorizer
          scopes: # Optional
            - user.id
            - user.email

What is wrong with the events section?

10
  • Why is the path a '*'? Did you mean '/'?
    – ultimoTG
    Commented Sep 26, 2020 at 18:55
  • I want all paths to be handled by this function. Anyway if i use path: '/' I still get the warning Commented Sep 26, 2020 at 23:39
  • Since you're trying to catch all methods and any path, try this events: - httpApi: '*' as decribed here - serverless.com/framework/docs/providers/aws/events/http-api/…
    – ultimoTG
    Commented Sep 27, 2020 at 0:09
  • Removed method and path and added wildcard. With that I get: Configuration warning at 'functions.app.events[0]': unrecognized property 'authorizer' Commented Sep 27, 2020 at 0:14
  • Authorizer config is probably not supported for catch all and any scenarios? I'm not sure though, it doesn't say that anywhere in the docs.
    – ultimoTG
    Commented Sep 27, 2020 at 0:16

3 Answers 3

69

The issue is indeed indentation. The indentation on this is weird so I will explain it below. Every · is a space:

functions:
··hello:
····handler: handler.hello
····events:
······- http:
··········path: /hello
··········method: get

Some pointers:

  • There is a space after the - http: hyphen.
  • The next line is indented oddly - this is what's causing the issue. Rather than just two spaces of indent after defining our event type (http in my case), there are actually 4. I don't know why but that's what it demands.

Another tip: if you find your text editor is auto-formatting your YAML file and replacing the space indentation with tabs or whatever, add a .editorconfig file to the root with these settings:

[*.yml]
indent_size = 2
indent_style = spaces
3
  • 4
    You saved my day... and now let somebody tell me that hunting for missing ; is bigger problem than hunting for missing two spaces... I almost pulled half of my hair today.
    – Greg0ry
    Commented Mar 10, 2021 at 11:06
  • 3
    dude. You just made my day. It just requires 4 spaces below - http: THANK YOU SO MUCH Commented Mar 22, 2021 at 15:39
  • My hero, seriously.
    – Heydiddly
    Commented Jan 12, 2022 at 11:59
34

I had a similar issue. The problem was with indentation. Try to fix it like this:

- httpApi:
    method: '*'
    path: '*'
0
0

I found the similer issue, I solve by remove the prefix sapace from http

events: - http: path: /PostFunction method: POST

this is the correct one events:

  • http: path: /PostFunction method: POST

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.