How are 'template' and 'pattern' used for response definitions?

Hello,
I need more information regarding how to use the ‘template’ & ‘pattern’ keys when defining a REST API. The example that I see in the docs is below. However, I can’t find any documentation about how to define the values for these keys. I assume it is there somewhere, but so far I’ve come up short.
Thanks.

functions:
  create:
    handler: posts.create
    events:
      - http:
          method: post
          path: whatever
          integration: lambda
          response:
            headers:
              Content-Type: "'text/html'"
            template: $input.path('$')
            statusCodes:
              201:
                pattern: '' # Default response method
              409:
                pattern: '.*"statusCode":409,.*' # JSON response
                template: $input.path("$.errorMessage") # JSON return object
                headers:
                  Content-Type: "'application/json+hal'"

NM. After lots of digging, I determined that what I was trying to do required an entry in the ‘resources’ section of the template.yml file (shown below). Lots of digging required. Very slow going…

 badRequestBodyResponse:
      Type: AWS::ApiGateway::GatewayResponse
      Properties:
        ResponseTemplates:
          application/json : "{\n     \"message\": $context.error.validationErrorString,\n     \"type\":  \"$context.error.responseType\",\n     \"stage\":  \"$context.stage\",\n     \"resourcePath\":  \"$context.resourcePath\",\n     \"stageVariables.a\":  \"$stageVariables.a\",\n     \"statusCode\": \"'400'\"\n}"
        ResponseType: 'BAD_REQUEST_BODY'
        RestApiId: !Ref ApiGatewayRestApi
        StatusCode: '400'