【发布时间】:2020-10-05 04:13:01
【问题描述】:
我正在为 Amazon Forecast 编写一个 boto3 服务员。专门用于数据集导入作业。为此,我正在使用 DescribeDataset 操作。这个想法是等到导入作业处于活动状态时,才能在同一个 Lambda 函数或另一个函数中创建一个预测器。
参数的选择/接受器中的预期
Status (string) --
The status of the dataset. States include:
ACTIVE
CREATE_PENDING , CREATE_IN_PROGRESS , CREATE_FAILED
DELETE_PENDING , DELETE_IN_PROGRESS , DELETE_FAILED
UPDATE_PENDING , UPDATE_IN_PROGRESS , UPDATE_FAILED
The UPDATE states apply while data is imported to the dataset from a call to the CreateDatasetImportJob operation and reflect the status of the dataset import job. For example, when the import job status is CREATE_IN_PROGRESS, the status of the dataset is UPDATE_IN_PROGRESS.
我使用以下链接作为配置服务员的指南。 https://www.2ndwatch.com/blog/use-waiters-boto3-write/
这看起来很简单,但在创建服务员时并没有什么可做的。我对 boto3 和 Lambda 很陌生。我是否犯了简单的错误、遗漏了某些内容或误解了服务员的工作方式?
感谢任何帮助。
waiter.wait() 的 DatasetArn 参数是正确的
在 Lambda 中测试以下代码后,我收到以下错误。我在目标和相关导入作业开始后不久手动运行测试。导入作业激活后执行成功。
{
"errorMessage": "2020-06-15T15:13:21.144Z a9c5019d-94c8-4332-863e-3bac2a6c8b7f Task timed out after 3.00 seconds"
}
import boto3
from botocore.exceptions import WaiterError
from botocore.waiter import WaiterModel
from botocore.waiter import create_waiter_with_client
forecast = boto3.client('forecast')
def lambda_handler(event, context):
delay = 10
max_attempts = 15
waiter_name = 'TargetImportJobStatus'
waiter_config = {
'version': 2,
'waiters': {
'TargetImportJobStatus': {
'operation': 'DescribeDataset',
'delay': delay,
'maxAttempts': max_attempts,
'acceptors': [
{
'matcher': 'path',
'expected': 'ACTIVE',
'argument': 'Status',
'state': 'success'
},
{
'matcher': 'path',
'expected': 'UPDATE_PENDING',
'argument': 'Status',
'state': 'retry'
},
{
'matcher': 'path',
'expected': 'UPDATE_IN_PROGRESS',
'argument': "Status",
'state': 'retry'
},
{
'matcher': 'path',
'expected': 'UPDATE_FAILED',
'argument': 'Status',
'state': 'failure'
}
],
}
}
}
waiter_model = WaiterModel(waiter_config)
custom_waiter = create_waiter_with_client(waiter_name, waiter_model, forecast)
try:
custom_waiter.wait(
DatasetArn=target_dataset_arn
)
except WaiterError as e:
print(e)
w_name = 'RelatedImportJobStatus'
w_config = {
'version': 2,
'waiters': {
'RelatedImportJobStatus': {
'operation': 'DescribeDataset',
'delay': delay,
'maxAttempts': max_attempts,
'acceptors': [
{
'matcher': 'path',
'expected': 'ACTIVE',
'argument': 'Status',
'state': 'success'
},
{
'matcher': 'path',
'expected': 'UPDATE_PENDING',
'argument': 'Status',
'state': 'retry'
},
{
'matcher': 'path',
'expected': 'UPDATE_IN_PROGRESS',
'argument': 'Status',
'state': 'retry'
},
{
'matcher': 'path',
'expected': 'UPDATE_FAILED',
'argument': 'Status',
'state': 'failure'
}
],
}
}
}
w_model = WaiterModel(waiter_config)
w_waiter = create_waiter_with_client(waiter_name, waiter_model, forecast)
try:
w_waiter.wait(
DatasetArn=related_dataset_arn
)
except WaiterError as e:
print(e)
【问题讨论】:
标签: amazon-web-services aws-lambda boto3 botocore