0
votes

I used Serverless to set up an AWS Lambda API, which works fine via Postman, but which threw a CORS error when I attempted to access it from my Vuejs app.

I added the following to my serverless.yml:

functions:
  [app-name]:
    handler: index.handler
    events:
      - http: ANY /
          cors: true
      - http: 'ANY {proxy+}'
          cors: true

and now on sls deploy I get:

Y A M L Exception --------------------------------------
 
  bad indentation of a mapping entry in "/Users...-api/serverless.yml" at line 34, column 15:
                cors:
                    ^

I have tried other indentations and no indentation, but it does not help.

1

1 Answers

0
votes

You can use the following structure to enable cors from the serverless for your rest APIs.

- HTTP:
    path: /register
    method: POST
    cors:
        origins:
            - '*'