在 this tutorial写的是:
Set reasonable timeout periods, and report when they're about to be exceeded
If an operation doesn't execute within its defined timeout period, the function raises an exception and no response is sent to CloudFormation.
To avoid this, ensure that the timeout value for your Lambda functions is set high enough to handle variations in processing time and network conditions. Consider also setting a timer in your function to respond to CloudFormation with an error when a function is about to time out; this can help prevent function timeouts from causing custom resource timeouts and delays.
这背后的具体解决方案是什么?我应该在 AWS Lambda 上实现超时吗 或者我可以在 CustomResource 属性中设置超时时间?
最佳答案
据我所知,您无法在 CustomResource 上设置超时。 他们在您的引文中所写的是,您可以在函数超时之前向 Cloudformation 发出信号。
您可以通过查询上下文对象(处理函数中的第二个参数)来了解剩余时间。例如Python :
def handler(event, context):
print("Time left:", context.get_remaining_time_in_millis())
您将看到其他语言中的方法调用类似,例如 Java :
context.getRemainingTimeInMillis()
因此,您可以查询循环中的剩余时间,当该值变低(例如 3000 毫秒)时,检查您的资源是否仍未创建并向 Cloudformation 发送错误信号。
其次,请按照他们的建议增加函数的超时时间。
关于amazon-web-services - Cloudformation资源创建/删除超时时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50349045/