I am using lambda integration. Returning the success response works fine. Returning error is received as success in client.
I tried using `callback(new Error('[404] Not found'));` , `callback(null, { statusCode: 404, body: 'Not found', headers: { 'Content-Type': 'text/plain' } });` , tried with custom status code too but no luck.
Here is sample yml for helloworld function:
helloworld:
handler: helloWorld/handler.hello
timeout: 15
events:
- http:
path: hello/worlds
method: get
integration: lambda
request:
template:
application/json: "${file(helloWorld/test.vtl)}"
response:
headers:
Access-Control-Allow-Origin: "'*'"
Content-Type: "'application/json'"
template: $input.path('$.errorMessage')
cors:
origin: '*'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- Startlower
- Text
- Access-Control-Allow-Headers
- Access-Control-Allow-Origin
allowCredentials: false
authorizer:
name: ftAuth
type: request
package:
include: # Specify the directories and files which should be included in the deployment package for this specific function.
- helloWorld/**
I almost always use the proxy integration so I’m not fully prepared for this.
Before using serverless I fallowed this guide:
Hope it helps
1 Like