amazon-web-services - Cloudformation资源创建/删除超时时间

标签 amazon-web-services aws-lambda aws-cloudformation

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/

相关文章:

amazon-web-services - AWS cloudwatch CPU利用率与实际使用情况不符

amazon-web-services - 谷歌云有没有像AWS一样的存储网关概念?

ios - "message": "Internal server error" issue with Lambda/API Gateway and iOS

amazon-web-services - 无法将现有 CloudFormation 模板的元数据 (AWS::CloudFormation::Init) 部分迁移到 AWS CDK

amazon-web-services - 在不同区域创建 Amazon Kinesis 数据生成器堆栈

amazon-web-services - AWS RDS : FATAL: password authentication failed for user "postgres"

python - 如何使用 boto3 删除 AWS 存储桶中的文件夹及其内容

docker - 在Mac OS X上通过 `-it`命令提取图像后如何进入docker容器?

aws-lambda - 在localstack中创建API网关

amazon-web-services - 用户登录时登录抛出 'Incorrect username or password' 错误