How to set cors origin to request origin in preflight request

i basically just want to use this response template to accept credentials from any origin

#set($origin = $input.params("Origin"))
#if($origin == "") #set($origin = $input.params("origin")) #end
#set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)

to handle cors instead of the default one of the doc

Serverless.yml

cors:
    allowCredentials: true
    origin: 'i want to match the request origin'