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?

Cadoiz
  • 1,446
  • 21
  • 31
Greg Pagendam-Turner
  • 2,356
  • 5
  • 32
  • 49
  • Why is the path a '*'? Did you mean '/'? – ultimoTG Sep 26 '20 at 18:55
  • I want all paths to be handled by this function. Anyway if i use path: '/' I still get the warning – Greg Pagendam-Turner Sep 26 '20 at 23:39
  • Since you're trying to catch all methods and any path, try this `events: - httpApi: '*'` as decribed here - https://www.serverless.com/framework/docs/providers/aws/events/http-api/#catch-alls – ultimoTG Sep 27 '20 at 00:09
  • Removed method and path and added wildcard. With that I get: Configuration warning at 'functions.app.events[0]': unrecognized property 'authorizer' – Greg Pagendam-Turner Sep 27 '20 at 00: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 Sep 27 '20 at 00:16
  • In that case if I specified: method: 'GET' path: '/' then I shouldn't get: unsupported function event. - but I do – Greg Pagendam-Turner Sep 27 '20 at 00:29
  • Right, not sure what could be causing it. Try `events: - httpApi: '*'` but do not include the `authorizer` just to see if it still complains – ultimoTG Sep 27 '20 at 00:41
  • Found the schema for the function event in the source files - https://github.com/serverless/serverless/blob/b867df147aea5e1f57a9d275e2a389efbbcf38aa/lib/plugins/aws/package/compile/events/httpApi/index.js#L55-L85 and from looking at it, your YAML definition looks good except may be the indentation. Try fixing the indentations, never know if that's the issue. Also, btw, do you have the authorizer provider set up like here - https://www.serverless.com/framework/docs/providers/aws/events/http-api#1-configure-authorizers-on-providerhttpapiauthorizers? – ultimoTG Sep 27 '20 at 00:57
  • Doesn't create the error when I remove the authorizer section in events. I do have an authorizer on the API as per the link. I'm wondering if this is a false error. Will see if I can deploy anyway – Greg Pagendam-Turner Sep 27 '20 at 01:01
  • I'd recommend using a linter extension like the one for VSCode (kddejong.vscode-cfn-lint - I don't know your IDE) to parse your template and show problems with it. – Cadoiz Sep 09 '21 at 09:07

3 Answers3

62

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
MSOACC
  • 3,074
  • 2
  • 29
  • 50
33

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

- httpApi:
    method: '*'
    path: '*'
Cadoiz
  • 1,446
  • 21
  • 31
nekh
  • 339
  • 2
  • 5
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