from chalice import Chalice
app = Chalice(app_name='myapp')
def custom_middleware_one(event, context):
# This middleware will be executed before reaching the route handler.
# You can perform actions here such as logging, authentication, etc.
print("Executing custom middleware one")
return event
def custom_middleware_two(event, context):
# This is another middleware function.
print("Executing custom middleware two")
return event
@app.route('/')
def index():
return {'message': 'Hello, Chalice!'}
# Apply the middleware functions to the app
app.register_middleware(custom_middleware_one, 'all')
app.register_middleware(custom_middleware_two, 'all')
if __name__ == '__main__':
app.debug = True
app.run()