# Lambda error regex not working

**URL:** <https://forum.serverless.com/t/lambda-error-regex-not-working/20371>\
**Category:** Serverless Framework\
**Tags:** lambda, api-gateway\
**Created:** [July 25, 2024, 11:46am UTC](https://forum.serverless.com/t/lambda-error-regex-not-working/20371 "2024-07-25T11:46:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmack](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@dmack](https://forum.serverless.com/u/dmack)\
**Post date:** [July 25, 2024, 11:46am UTC](https://forum.serverless.com/t/lambda-error-regex-not-working/20371/1 "2024-07-25T11:46:03Z")

</div>

Hi team,

I am using an API gateway connected to a Lambda function.

The Lambda function response is returning:

Response

{  
“statusCode”: 400,  
“body”: “{"errorType":"UserLambdaValidationException","message":"PreSignUp failed with error [UserAlreadyExists] Registration failed. A user with that email already exists…"}”  
}

Lambda Error Regex: ._“errorType”:“UserLambdaValidationException”._

Yet when I test via API gateway or Postman it is still returning a 200 OK response.

I have tried a variety of different response formats and regex combinations.

Any suggestions or ideas?

Thank you,  
David

---

<div class="post-metadata">

**Author:** ![dazes97](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dazes97/32/7962_2.png) [@dazes97](https://forum.serverless.com/u/dazes97)\
**Post date:** [July 25, 2024, 3:54pm UTC](https://forum.serverless.com/t/lambda-error-regex-not-working/20371/2 "2024-07-25T15:54:36Z")

</div>

could you share your yml file?

---

<div class="post-metadata">

**Author:** ![dmack](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@dmack](https://forum.serverless.com/u/dmack)\
**Post date:** [July 26, 2024, 10:29am UTC](https://forum.serverless.com/t/lambda-error-regex-not-working/20371/3 "2024-07-26T10:29:09Z")

</div>

Hi, I am using AWS Console

---

<div class="post-metadata">

**Author:** ![dmack](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@dmack](https://forum.serverless.com/u/dmack)\
**Post date:** [July 27, 2024, 2:57am UTC](https://forum.serverless.com/t/lambda-error-regex-not-working/20371/4 "2024-07-27T02:57:48Z")

</div>

Thanks for your reply. I have exported my current config… please see below and let me know if you have any thoughts or feedback.

```auto
/register:
  post:
    produces:
    - "application/json"
    responses:
      "200":
        description: "200 response"
        schema:
          $ref: "#/definitions/Empty"
        headers:
          Access-Control-Allow-Origin:
            type: "string"
      "400":
        description: "400 response"
        schema:
          $ref: "#/definitions/Empty"
        headers:
          Access-Control-Allow-Origin:
            type: "string"
    x-amazon-apigateway-integration:
      type: "aws"
      httpMethod: "POST"
      uri: "arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:<ACCOUNT_ID>:function:<FUNCTION NAME>/invocations"
      responses:
        default:
          statusCode: "200"
        ".*\"errorType\":\"UserLambdaValidationException\".*":
          statusCode: "400"
          responseParameters:
            method.response.header.Access-Control-Allow-Origin: "'*'"
          responseTemplates:
            application/json: "#set($inputRoot = $input.path('$'))\r\n{\r\n \"\
              statusCode\": \"$inputRoot.statusCode\",\r\n \"body\": $input.json('$.body')\r\
              \n}\r\n"
      passthroughBehavior: "when_no_match"
      contentHandling: "CONVERT_TO_TEXT"
definitions:
  Empty:
    type: "object"
    title: "Empty Schema"
x-amazon-apigateway-gateway-responses:
  DEFAULT_4XX:
    responseParameters:
      gatewayresponse.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
      gatewayresponse.header.Access-Control-Allow-Credentials: "'true'"
      gatewayresponse.header.Access-Control-Allow-Origin: "'https://localhost:3000'"
      gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
  DEFAULT_5XX:
    responseParameters:
      gatewayresponse.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
      gatewayresponse.header.Access-Control-Allow-Credentials: "'true'"
      gatewayresponse.header.Access-Control-Allow-Origin: "'https://localhost:3000'"
      gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"

```
