How to print complete http request using chalice?
Question:
I have a small application where I am using chalice to expose some endpoints. For logging purpose I want to print the entire url whenever any handler function is called.
@app.route('/XYZ', methods=['GET'])
@logging_and_error_handling()
def get_XYZ_value():
For example , if the above function gets called, I want to log the entire url using app.log.info()
.
Something like call to http://myhostname.com/api/XYZ started
I tried using app.current_request.to_dict()
, but it looks like it doesn’t have that info. Git reference.
Is there an alternate way to achieve this ?
Answers:
I use app.current_request.context['resourcePath']
for the URL and also log the following as well:
app.current_request.method
app.current_request.uri_params
app.current_request.query_params
app.current_request.context.get('requestId')
Maybe you can use app.current_request.context['Path']
, not use app.current_request.context['resourcePath']
if
path of custom domain api mapping is: xxxxx
your custom domain is: a.com
when a client is using a.com/xxxxx/XYZ
to access your lambda,
app.current_request.context['resourcePath']
will be "/XYZ",
and app.current_request.context['Path']
will be "/xxxxx/XYZ"
I have a small application where I am using chalice to expose some endpoints. For logging purpose I want to print the entire url whenever any handler function is called.
@app.route('/XYZ', methods=['GET'])
@logging_and_error_handling()
def get_XYZ_value():
For example , if the above function gets called, I want to log the entire url using app.log.info()
.
Something like call to http://myhostname.com/api/XYZ started
I tried using app.current_request.to_dict()
, but it looks like it doesn’t have that info. Git reference.
Is there an alternate way to achieve this ?
I use app.current_request.context['resourcePath']
for the URL and also log the following as well:
app.current_request.method
app.current_request.uri_params
app.current_request.query_params
app.current_request.context.get('requestId')
Maybe you can use app.current_request.context['Path']
, not use app.current_request.context['resourcePath']
if
path of custom domain api mapping is: xxxxx
your custom domain is: a.com
when a client is using a.com/xxxxx/XYZ
to access your lambda,
app.current_request.context['resourcePath']
will be "/XYZ",
and app.current_request.context['Path']
will be "/xxxxx/XYZ"