# API gateway CORS error if I pass cors in provider level

**URL:** <https://forum.serverless.com/t/api-gateway-cors-error-if-i-pass-cors-in-provider-level/20980>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, api-gateway\
**Created:** [February 12, 2025, 7:05am UTC](https://forum.serverless.com/t/api-gateway-cors-error-if-i-pass-cors-in-provider-level/20980 "2025-02-12T07:05:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zil31](https://avatars.discourse-cdn.com/v4/letter/z/5f9b8f/32.png) [@zil31](https://forum.serverless.com/u/zil31)\
**Post date:** [February 12, 2025, 7:05am UTC](https://forum.serverless.com/t/api-gateway-cors-error-if-i-pass-cors-in-provider-level/20980/1 "2025-02-12T07:05:04Z")

</div>

Hello, I am using serverless + API gateway and facing cors error if I pass custom headers.

I am adding cors configuration on the function level, and then it’s working fine, but at the provider level it’s not doing anything. So, if I pass the cors configuration to provider level, then it’s not working fine.  
Can anyone help with this? How to do it at the provider level?

```auto
/* eslint-disable import/no-import-module-exports */
/* eslint-disable no-template-curly-in-string */
import type { AWS } from '@serverless/typescript';

const serverlessConfig: AWS = {
  service: 'epicpass',
  frameworkVersion: '3',
  plugins: ['serverless-esbuild'],
  provider: {
    name: 'aws',
    runtime: 'nodejs20.x',
    versionFunctions: false,
    stage: '${opt:stage, "sandbox"}',
    region: 'ap-south-1',
    iam: { role: { statements: [{ Effect: 'Allow', Action: '*', Resource: '*' }] } },
    environment: {
      STAGE: '${self:provider.stage}',
      REGION: '${self:provider.region}',
    },
    httpApi: {
      cors: {
        allowedOrigins: ['*'],
        allowedHeaders: ['*'],
        allowedMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
        allowCredentials: false,
      },
    },
  },
  custom: {
    esbuild: {
      bundle: true,
      minify: false,
      tsconfig: 'tsconfig.json',
      exclude: ['@aws-sdk/*', 'aws-sdk'],
      target: 'node20',
      define: { 'require.resolve': undefined },
      platform: 'node',
      concurrency: 10,
    },
  },
  package: {
    patterns: ['!node_modules/**', '!package.json', '!package-lock.json'],
  },
  functions: {
    AdminDashboard: {
      handler: 'src/functions/v1/admin-api/dashboard/handler.api',
      events: [
        { http: { path: '/v1/admins/testimonials', method: 'POST', cors: { headers: ['*'] } } },
      ],
    },
  },
};

module.exports = serverlessConfig;

```

---

<div class="post-metadata">

**Author:** ![beenmeckel](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@beenmeckel](https://forum.serverless.com/u/beenmeckel)\
**Post date:** [April 23, 2025, 8:59pm UTC](https://forum.serverless.com/t/api-gateway-cors-error-if-i-pass-cors-in-provider-level/20980/2 "2025-04-23T20:59:02Z")

</div>

I have an API with a Lambda integration deployed to API Gateway. I have an OPTIONS method set up and am passing my CORS headers back to API Gateway from my Lambda, but am still receiving the following error: [9Apps](https://9apps.ooo/) [Tutuapp](https://tutuapp.uno/)
