要启用API Gateway的CORS(跨源资源共享),您需要进行以下步骤:
aws apigateway put-method-response \
--rest-api-id \
--resource-id \
--http-method OPTIONS \
--status-code 200 \
--response-models "{\"application/json\": \"Empty\"}"
aws apigateway put-method-response \
--rest-api-id \
--resource-id \
--http-method \
--status-code 200 \
--response-models "{\"application/json\": \"Empty\"}"
aws apigateway put-integration-response \
--rest-api-id \
--resource-id \
--http-method \
--status-code 200 \
--response-templates "{\"application/json\": \"\"}"
aws apigateway create-deployment \
--rest-api-id \
--stage-name
注意:请将
替换为您的API Gateway的REST API ID,
替换为资源的ID,
替换为您的HTTP方法(如GET,POST等),
替换为您的API Gateway的阶段名称。
aws apigateway put-method \
--rest-api-id \
--resource-id \
--http-method \
--authorization-type "NONE" \
--request-parameters "{\"method.request.header.Origin\": false}" \
--request-models "{\"application/json\": \"Empty\"}"
aws apigateway put-integration-response \
--rest-api-id \
--resource-id \
--http-method \
--status-code 200 \
--response-templates "{\"application/json\": \"\"}"
aws apigateway create-deployment \
--rest-api-id \
--stage-name
同样,请将
替换为您的API Gateway的REST API ID,
替换为资源的ID,
替换为您的HTTP方法(如GET,POST等),
替换为您的API Gateway的阶段名称。
aws apigateway create-deployment \
--rest-api-id \
--stage-name
同样,请将
替换为您的API Gateway的REST API ID,
替换为您的API Gateway的阶段名称。
完成上述步骤后,您的API Gateway将启用CORS,并允许跨源请求。