Testar o CORS para uma API do API Gateway - Amazon API Gateway

Testar o CORS para uma API do API Gateway

É possível testar a configuração de CORS da API invocando a API e verificando os cabeçalhos de CORS na resposta. O comando curl a seguir envia uma solicitação OPTIONS para uma API implantada.

curl -v -X OPTIONS https://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}
< HTTP/1.1 200 OK < Date: Tue, 19 May 2020 00:55:22 GMT < Content-Type: application/json < Content-Length: 0 < Connection: keep-alive < x-amzn-RequestId: a1b2c3d4-5678-90ab-cdef-abc123 < Access-Control-Allow-Origin: * < Access-Control-Allow-Headers: Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token < x-amz-apigw-id: Abcd= < Access-Control-Allow-Methods: DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT

Os cabeçalhos Access-Control-Allow-Origin, Access-Control-Allow-Headers e Access-Control-Allow-Methods na resposta mostram que a API oferece suporte ao CORS. Para ter mais informações, consulte CORS para APIs REST no API Gateway.