首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >成功生成CLI令牌后,MWAA生成的Cli令牌返回403

成功生成CLI令牌后,MWAA生成的Cli令牌返回403
EN

Stack Overflow用户
提问于 2022-03-16 00:29:54
回答 1查看 126关注 0票数 0

描述

代码

代码语言:javascript
复制
from datetime import datetime

import requests
import boto3

TODAYS_DATE = datetime.now()

def main():
    mwaa_client = boto3.client('mwaa')
    response = mwaa_client.create_cli_token(Name="dev-main-mwaa-env")

    headers = {
        'Authorization': response["CliToken"],
        'Content-Type': 'text/plain'
    }

    dag_to_run = f"test_dag"

    mwaa_hostname = f'https://{response["WebServerHostname"]}/aws_mwaa/cli'

    # NOTE: The execution date is a required part of the call. I'm unsure
    #       why they didn't accept the run_id.
    dag_status_response = requests.post(
        mwaa_hostname,
        headers=headers,
        data=f"dags state {dag_to_run} {TODAYS_DATE.isoformat()}")

    tasks_states_response = requests.post(
        mwaa_hostname,
        headers=headers,
        data=f"tasks states-for-dag-run -o json {dag_to_run} {TODAYS_DATE.isoformat()}")
    breakpoint()

if __name__ == "__main__":
    main()

PDB繁殖

代码语言:javascript
复制
(Pdb) ll
  8     def main():
  9         mwaa_client = boto3.client('mwaa')
 10         response = mwaa_client.create_cli_token(Name="dev-main-mwaa-env")                                                                                                                                                                                                                                                                                11
 12         headers = {
 13             'Authorization': response["CliToken"],
 14             'Content-Type': 'text/plain'
 15         }
 16
 17         dag_to_run = f"test_dag"
 18
 19         mwaa_hostname = f'https://{response["WebServerHostname"]}/aws_mwaa/cli'
 20
 21         dag_status_response = requests.post(
 22             mwaa_hostname,
 23             headers=headers,
 24             data=f"dags state {dag_to_run} {TODAYS_DATE.isoformat()}")
 25
 26         tasks_states_response = requests.post(
 27             mwaa_hostname,
 28             headers=headers,
 29             data=f"tasks states-for-dag-run -o json {dag_to_run} {TODAYS_DATE.isoformat()}")
 30  ->     breakpoint()
(Pdb) tasks_states_response
<Response [403]>
(Pdb) dag_status_response
<Response [403]>
(Pdb) headers
EN

回答 1

Stack Overflow用户

发布于 2022-03-16 00:29:54

修复

核心问题在于我是如何编写标题的。特别是从

代码语言:javascript
复制
'Authorization': response["CliToken"],

代码语言:javascript
复制
'Authorization': f'Bearer {response["CliToken"]}',

这甚至在我为这个示例阅读的AWS MWAA医生中进行了介绍。我只是错过了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71490516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档