lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js/generateCorsPreflightConfig
    const generateCorsPreflightConfig = (corsConfig, corsPreflightConfig, method) => {
      const headers = [
        'Content-Type',
        'X-Amz-Date',
        'Authorization',
        'X-Api-Key',
        'X-Amz-Security-Token',
      ];

      let newCorsPreflightConfig;

      const cors = {
        origins: ['*'],
        methods: ['OPTIONS'],
        headers,
      };

      if (typeof corsConfig === 'object') {
        Object.assign(cors, corsConfig);

        cors.methods = [];
        if (cors.headers) {
          if (!Array.isArray(cors.headers)) {
            const errorMessage = [
              'CORS header values must be provided as an array.',
              ' Please check the docs for more info.',
            ].join('');
            throw new this.serverless.classes
            .Error(errorMessage);
          }
        } else {
          cors.headers = headers;
        }

        if (cors.methods.indexOf('OPTIONS') === NOT_FOUND) {
          cors.methods.push('OPTIONS');
        }

        if (cors.methods.indexOf(method.toUpperCase()) === NOT_FOUND) {
          cors.methods.push(method.toUpperCase());
        }
      } else {
        cors.methods.push(method.toUpperCase());
      }

      if (corsPreflightConfig) {
        cors.methods = _.union(cors.methods, corsPreflightConfig.methods);
        cors.headers = _.union(cors.headers, corsPreflightConfig.headers);
        cors.origins = _.union(cors.origins, corsPreflightConfig.origins);
        newCorsPreflightConfig = _.merge(corsPreflightConfig, cors);
      } else {
        newCorsPreflightConfig = cors;
      }

      return newCorsPreflightConfig;
    };