I have created a very simple Google Cloud Run Python service to experiment with Restful APIs:
import os
from flask import Flask
app = Flask(__name__)
@app.route('/user/<user_name>', methods=['PUT'])
def create_user(user_name):
return 'created!', 200
@app.route('/user/<user_name>', methods=['DEL'])
def delete_user(user_name):
return 'deleted!', 200
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
I have managed to successfully deploy this service to Cloud Run using this Dockerfile.
To test the service, I use curl
to hit the deployed endpoint:
$curl -X PUT https://testapi.xxxxxxxx.a.run.app/user/prl900
created!
However, the DEL request causes a 502 error, and mysteriously this is not logged in Cloud Run's logging platform.
$curl -X DEL https://testapi.xxxxxxxx.a.run.app/user/prl900
...
...
<p><b>502.</b> <ins>That’s an error.</ins>
<p>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds. <ins>That’s all we know.</ins>
All other methods are rejected and are correctly logged in the backend, as expected:
$curl -X PATCH https://testapi.xxxxxxxx.a.run.app/user/prl900
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
Can anyone understand the reason for Cloud Run failing to process DEL requests and not logging them? Is there anything special about DEL requests on Cloud Run? The service works fine on my local computer.
Thanks for your help