为什么 Lambda 突然抛出“请求已过期”错误?

Daw*_*y33 0 python amazon-web-services boto3 aws-lambda

我的Lambda函数通过create_instancesboto3模块创建EC2服务器。

我从早上就开始触发这个 Lambda,它创建实例的效果很好。但突然间,我不断收到这个奇怪的错误:

{
  "stackTrace": [
    [
      "/var/task/processing.py",
      54,
      "lambda_handler",
      "KeyName=keyname, SubnetId='subnet-<>', SecurityGroupIds=['sg-<>'])"
    ],
    [
      "/var/runtime/boto3/resources/factory.py",
      520,
      "do_action",
      "response = action(self, *args, **kwargs)"
    ],
    [
      "/var/runtime/boto3/resources/action.py",
      83,
      "__call__",
      "response = getattr(parent.meta.client, operation_name)(**params)"
    ],
    [
      "/var/task/botocore/client.py",
      251,
      "_api_call",
      "return self._make_api_call(operation_name, kwargs)"
    ],
    [
      "/var/task/botocore/client.py",
      537,
      "_make_api_call",
      "raise ClientError(parsed_response, operation_name)"
    ]
  ],
  "errorType": "ClientError",
  "errorMessage": "An error occurred (RequestExpired) when calling the RunInstances operation: Request has expired."
}
Run Code Online (Sandbox Code Playgroud)

发生了什么事?很确定这不是代码错误,因为从早上起就一直在运行相同的代码。

rba*_*ish 5

就我而言,发生这种情况是因为我的凭证aws_session_token已过期,我必须替换所有凭证详细信息:

  1. aws_access_key_id
  2. aws_secret_access_key
  3. aws_session_token

替换所有详细信息后,错误不存在。