【问题标题】:"Connect timeout on endpoint URL" when running cron job运行 cron 作业时“端点 URL 连接超时”
【发布时间】:2019-12-24 01:31:32
【问题描述】:

我设置了一个 crontab 文件来运行一个 Python 脚本,该脚本创建一个 JSON 文件并将其写入 S3 存储桶。从命令行执行时它按预期运行,但是当我将它作为 cron 作业运行时,我收到以下错误:

botocore.exceptions.ConnectTimeoutError:端点 URL 连接超时

这是脚本中以下代码行的结果:

import boto3

def main():
    # Create EC2 client and get EC2 response
    ec2 = boto3.client('ec2')
    response = ec2.describe_instances()

我的猜测是 cron 作业中没有设置某些权限,拒绝我访问该 URL。

【问题讨论】:

    标签: amazon-web-services amazon-ec2 cron


    【解决方案1】:

    事实证明,我必须设置代理设置,以便我以自己而不是 root 身份访问 AWS。我将 cron 作业作为 Linux shell 脚本而不是 Python 脚本运行,并导出了我在 shell 脚本第一行的 ~/.bash_profile 中找到的 http_proxy、https_proxy 和 no_proxy 设置

    `export http_proxy=<http_proxy from ~/.bash_profile>
     export https_proxy=<https_proxy from ~/.bash_profile>
     export no_proxy=<no_proxy from ~./bash_profile>
     python <python script>`
    

    【讨论】:

      猜你喜欢
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      • 2018-02-08
      • 2021-10-30
      • 2017-02-27
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      相关资源
      最近更新 更多