编写 Python 金丝雀脚本 - Amazon CloudWatch
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

编写 Python 金丝雀脚本

此脚本将成功通过一次运行,并返回一个字符串。要查看失败的金丝雀示例,请将 fail = False 更改为 fail = True

def basic_custom_script(): # Insert your code here # Perform multi-step pass/fail check # Log decisions made and results to /tmp # Be sure to wait for all your code paths to complete # before returning control back to Synthetics. # In that way, your canary will not finish and report success # before your code has finished executing fail = False if fail: raise Exception("Failed basicCanary check.") return "Successfully completed basicCanary checks." def handler(event, context): return basic_custom_script()

将 Python 金丝雀文件打包

如果您有多个 .py 文件或脚本具有依赖项,则您可以将它们捆绑到单个 ZIP 格式文件中。如果您使用 syn-python-selenium-1.1 运行时,此 ZIP 格式文件必须将主金丝雀 .py 文件包含在 python 文件夹中,例如 python/my_canary_filename.py。如果您使用 syn-python-selenium-1.1 或之后版本,您可以选择使用其他文件夹,例如 python/myFolder/my_canary_filename.py

此 ZIP 格式文件应包含所有必要的文件夹和文件,但其他文件不需要位于 python 文件夹中。

请务必将您的金丝雀脚本入口点设置为 my_canary_filename.functionName,以匹配脚本入口点的文件名和函数名称。如果您使用 syn-python-selenium-1.0 运行时,则 functionName 必须是 handler。如果您使用 syn-python-selenium-1.1 或之后版本,该处理程序名称限制不适用,您也可以选择将金丝雀存储在单独的文件夹中,例如 python/myFolder/my_canary_filename.py。如果将其存储在单独的文件夹中,请在脚本入口点中指定该路径,例如 myFolder/my_canary_filename.functionName