尝试使用 Boto3 调用 Lamba 时出现 InvalidSignatureException
InvalidSignatureException while trying to Invoke Lamba using Boto3
我正在使用 'RequestResponse' 调用类型调用 aws lambda 函数并收到此错误:
我已经搜索过其他 aws SDK 支持的解决方案,但找不到 python boto3 的任何解决方案。
编辑:我正在使用 AWS Glue python shell 作业来 运行 我的代码,所以我无法控制系统时间。
Traceback (most recent call last):
File "/tmp/glue-python-libs-dgQjkA/audit_api_handler.py", line 532, in get_jobs_by_job_types
return self.get_api_response(method, params)
File "/tmp/glue-python-libs-dgQjkA/audit_api_handler.py", line 591, in get_api_response
LogType='Tail', Payload=json.dumps(post_data).encode())
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions
.
ClientError
:
An error occurred (InvalidSignatureException) when calling the Invoke operation: Signature expired: 20190712T122841Z is now earlier than 20190712T122841Z (20190712T123341Z - 5 min.)
AWS Glue 在虚拟实例上为您创建的每个 Glue 作业提供一个 Spark 环境运行。
时间同步问题很可能是由于粘合作业的底层实例无法通过 NTP 请求当前时间造成的。
如评论中所述,粘合作业配置了一个连接来访问数据存储。对于此配置,AWS 文档 [1] 指出:
If a job needs to run in your VPC subnet—for example, transforming data from a JDBC data store in a private subnet—AWS Glue sets up elastic network interfaces that enable your jobs to connect securely to other resources within your VPC.
[...]
No public IP addresses are assigned. [...]
If your job needs to access both VPC resources and the public internet, the VPC needs to have a Network Address Translation (NAT) gateway inside the VPC.
如评论中所确认,分配给粘合连接的 VPC 缺少 NAT 网关(用于数据存储访问)导致了 boto3 时间同步问题。
AWS Glue 在 VPC 的给定子网内为粘合连接创建一个单独的 ENI,并通过此 ENI 路由底层实例的所有流量。如果 ENI 无法将流量路由到外部世界,时间显然无法同步。
注意: 让我感到困惑的是,另一方面,AWS EC2 不需要 public 互联网访问来进行时间同步(如文档 [ 2]).因此,要么他们没有使用 EC2 来托管底层实例,要么没有根据文档进行配置。也许这个论坛上的 AWS 专家可以告诉我们更多信息??
参考资料
[1] https://docs.aws.amazon.com/glue/latest/dg/start-connecting.html
[2] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html
虽然我很欣赏@Martin Loper 的回答,因为它解释了问题的原因,但我无法从粘合作业中删除连接,因为它需要与数据库通信,而且我也无法添加 NAT在 VPC 中,因为这是一项安全要求。
当我在工作开始时使用它时,我的问题得到了解决:
boto3.setup_default_session(region_name="us-east-1")
它确保每个 boto3 客户端使用 us-east-1 作为其区域。
更新:
虽然频率低了很多,但这个问题仍然存在。
我正在使用 'RequestResponse' 调用类型调用 aws lambda 函数并收到此错误:
我已经搜索过其他 aws SDK 支持的解决方案,但找不到 python boto3 的任何解决方案。
编辑:我正在使用 AWS Glue python shell 作业来 运行 我的代码,所以我无法控制系统时间。
Traceback (most recent call last):
File "/tmp/glue-python-libs-dgQjkA/audit_api_handler.py", line 532, in get_jobs_by_job_types
return self.get_api_response(method, params)
File "/tmp/glue-python-libs-dgQjkA/audit_api_handler.py", line 591, in get_api_response
LogType='Tail', Payload=json.dumps(post_data).encode())
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions
.
ClientError
:
An error occurred (InvalidSignatureException) when calling the Invoke operation: Signature expired: 20190712T122841Z is now earlier than 20190712T122841Z (20190712T123341Z - 5 min.)
AWS Glue 在虚拟实例上为您创建的每个 Glue 作业提供一个 Spark 环境运行。
时间同步问题很可能是由于粘合作业的底层实例无法通过 NTP 请求当前时间造成的。
如评论中所述,粘合作业配置了一个连接来访问数据存储。对于此配置,AWS 文档 [1] 指出:
If a job needs to run in your VPC subnet—for example, transforming data from a JDBC data store in a private subnet—AWS Glue sets up elastic network interfaces that enable your jobs to connect securely to other resources within your VPC.
[...] No public IP addresses are assigned. [...]If your job needs to access both VPC resources and the public internet, the VPC needs to have a Network Address Translation (NAT) gateway inside the VPC.
如评论中所确认,分配给粘合连接的 VPC 缺少 NAT 网关(用于数据存储访问)导致了 boto3 时间同步问题。
AWS Glue 在 VPC 的给定子网内为粘合连接创建一个单独的 ENI,并通过此 ENI 路由底层实例的所有流量。如果 ENI 无法将流量路由到外部世界,时间显然无法同步。
注意: 让我感到困惑的是,另一方面,AWS EC2 不需要 public 互联网访问来进行时间同步(如文档 [ 2]).因此,要么他们没有使用 EC2 来托管底层实例,要么没有根据文档进行配置。也许这个论坛上的 AWS 专家可以告诉我们更多信息??
参考资料
[1] https://docs.aws.amazon.com/glue/latest/dg/start-connecting.html
[2] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html
虽然我很欣赏@Martin Loper 的回答,因为它解释了问题的原因,但我无法从粘合作业中删除连接,因为它需要与数据库通信,而且我也无法添加 NAT在 VPC 中,因为这是一项安全要求。 当我在工作开始时使用它时,我的问题得到了解决:
boto3.setup_default_session(region_name="us-east-1")
它确保每个 boto3 客户端使用 us-east-1 作为其区域。
更新: 虽然频率低了很多,但这个问题仍然存在。