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 ?

Asked By: Naxi

||

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')
Answered By: dmulter

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"

Answered By: Yang Ming
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.