# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 # CloudWatch Custom Widget sample: simple debugger, displays form and parameters passed to widget import json import os DOCS = """ ## Custom Widget Debugger A simpler "debugger" custom widget that prints out: * the Lambda **event** oject including the **widgetContext** parameter passed to the widget by CloudWatch Dashboards * the Lambda **context** object * the Lambda enivronment variables ### Widget parameters Just pass in any parameters you want to see how they are sent to the Lambda script. ### Example parameters ``` yaml --- param1: value param2: - entry1 - entry2 param3: sub: 7 ```""" def lambda_handler(event, context): if 'describe' in event: return DOCS form = event['widgetContext']['forms']['all'] input = form.get('input', '') stage = form.get('stage', 'prod') prettyEvent = json.dumps(event, indent=4, sort_keys=True) prettyContext = json.dumps(context.__dict__, indent=4, sort_keys=True, default=str) prettyEnv = "" for key, val in os.environ.items(): prettyEnv += f"{key}={val}\n" return f"""
{prettyEvent}
{prettyContext}
{prettyEnv}"""