Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Esempi di widget personalizzati per una dashboard CloudWatch
AWS fornisce esempi di widget personalizzati sia in Python che JavaScript in Python. Puoi creare questi widget di esempio utilizzando il link per ciascun widget in questo elenco. In alternativa, puoi creare e personalizzare un widget utilizzando la CloudWatch console. I collegamenti in questo elenco aprono una AWS CloudFormation console e utilizzano un collegamento di AWS CloudFormation creazione rapida per creare il widget personalizzato.
Puoi anche accedere agli esempi di widget personalizzati su. GitHub
Dopo questo elenco, vengono mostrati esempi completi del widget Echo per ogni lingua.
Widget Echo in JavaScript
Di seguito è riportato il widget di esempio di Echo in. JavaScript
const DOCS = ` ## Echo A basic echo script. Anything passed in the \`\`\`echo\`\`\` parameter is returned as the content of the custom widget. ### Widget parameters Param | Description ---|--- **echo** | The content to echo back ### Example parameters \`\`\` yaml echo: <h1>Hello world</h1> \`\`\` `; exports.handler = async (event) => { if (event.describe) { return DOCS; } let widgetContext = JSON.stringify(event.widgetContext, null, 4); widgetContext = widgetContext.replace(/</g, '<'); widgetContext = widgetContext.replace(/>/g, '>'); return `${event.echo || ''}<pre>${widgetContext}</pre>`; };
Widget Echo in Python
Di seguito è riportato il widget di esempio Echo in Python.
import json DOCS = """ ## Echo A basic echo script. Anything passed in the ```echo``` parameter is returned as the content of the custom widget. ### Widget parameters Param | Description ---|--- **echo** | The content to echo back ### Example parameters ``` yaml echo: <h1>Hello world</h1> ```""" def lambda_handler(event, context): if 'describe' in event: return DOCS echo = event.get('echo', '') widgetContext = event.get('widgetContext') widgetContext = json.dumps(widgetContext, indent=4) widgetContext = widgetContext.replace('<', '<') widgetContext = widgetContext.replace('>', '>') return f'{echo}<pre>{widgetContext}</pre>'
Widget Echo in Java
Di seguito è riportato il widget di esempio Echo in Java.
package example; import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class Handler implements RequestHandler<Event, String>{ static String DOCS = "" + "## Echo\n" + "A basic echo script. Anything passed in the ```echo``` parameter is returned as the content of the custom widget.\n" + "### Widget parameters\n" + "Param | Description\n" + "---|---\n" + "**echo** | The content to echo back\n\n" + "### Example parameters\n" + "```yaml\n" + "echo: <h1>Hello world</h1>\n" + "```\n"; Gson gson = new GsonBuilder().setPrettyPrinting().create(); @Override public String handleRequest(Event event, Context context) { if (event.describe) { return DOCS; } return (event.echo != null ? event.echo : "") + "<pre>" + gson.toJson(event.widgetContext) + "</pre>"; } } class Event { public boolean describe; public String echo; public Object widgetContext; public Event() {} public Event(String echo, boolean describe, Object widgetContext) { this.describe = describe; this.echo = echo; this.widgetContext = widgetContext; } }