ERROR REFERENCE
CORS preflight conflicts with an existing OPTIONS method
The template defines CORS twice: once through a Cors
configuration that auto-creates preflight handlers, and once through
an explicit OPTIONS method on the same path. API
Gateway refuses the duplicate, and the deploy fails.
WHAT IT MEANS
What this error means
SAM's Cors property on AWS::Serverless::Api
(or HttpApi) generates an OPTIONS preflight
method for each configured path. If an event source or an OpenAPI
definition also declares OPTIONS on that path — a common
leftover from handling CORS manually before adopting the shorthand —
the two definitions collide. The template says the same thing twice
in incompatible ways; neither one is wrong alone.
FIX
How to fix it
-
Pick one owner for preflight. Either keep the
Corsconfiguration and delete the explicitOPTIONSevent/method, or keep your handwrittenOPTIONShandler and drop theCorsblock. The shorthand is right for most APIs; the explicit method wins only when preflight needs custom logic. -
Check the OpenAPI definition too — an inline or
referenced
DefinitionBodycan carry the duplicateoptions:entry even when no event source declares it. -
Redeploy and verify preflight with a browser or
curl -X OPTIONSagainst the affected path — a 204 with the expectedAccess-Control-Allow-*headers.
AUTOMATE THE TRIAGE
Diagnose this automatically
SAM Doctor recognizes the duplicate-OPTIONS wording (medium confidence) in deploy logs. Runs locally; no AWS access, no log upload.
python -m pip install sam-doctor
sam-doctor diagnose deployment.log --format markdown
RELATED
Related errors
- The REST API doesn't contain any methods — the other API Gateway definition-ordering failure.
- InvalidSamDocumentException — when the template's shape, not its semantics, is the problem.