【问题标题】:{"message":"The security token included in the request is invalid."}{"message":"请求中包含的安全令牌无效。"}
【发布时间】:2019-07-04 12:07:07
【问题描述】:

我正在使用 serverless Now 作为通过 Slack API 调用 AWS 的工具。该脚本在本地和服务器上运行良好,但我在使用 Now Platform 时遇到问题。

这是我得到的错误:

{"message":"The security token included in the request is invalid."}

对此有几个问题,但他们似乎没有回答我的问题,因为我看到 AWS 凭证已正确配置运行 cat ~/.aws/credentials

我正在使用AWS Requests Auth

auth = AWSRequestsAuth(aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
                                   aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
                                   aws_host='restapiid.execute-api.us-east-1.amazonaws.com',
                                   aws_region='us-east-1',
                                   aws_service='execute-api')

headers = {"Content-Type":"application/json"}
response = requests.post('https://restapiid.execute-api.us-east-1.amazonaws.com/path', auth=auth, headers=headers, data=payload)

由于错误通常是 403,我怀疑是 Signature expired 问题,但我不知道如何将 Now 时间戳与 AWS 同步。

【问题讨论】:

    标签: python-3.x amazon-s3 slack-api vercel


    【解决方案1】:

    我的错:os.environ['AWS_ACCESS_KEY_ID']os.environ['AWS_SECRET_ACCESS_KEY'] 在 Now 平台中是 reserved variables。当您通过 slack API 或简单脚本在本地使用它们时,一切都很好,因为它将使用配置文件,但现在您需要存储和重命名它们:

    now secret add ak "[your aws access key]"
    now secret add sk "[your aws secret key]"
    now -e AWS_AK=@ak  -e AWS_SK=@sk
    

    所以你可以在你的代码中使用它们

    os.environ['AWS_AK']
    os.environ['AWS_SK']
    

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 2018-04-09
      • 2021-06-22
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-20
      相关资源
      最近更新 更多