如何获取AWS Sitewise Edge REST API的临时凭证?

0

【以下的问题经过翻译处理】 我如何在不使用OpsHub UI的情况下接收AWS Sitewise Edge REST API的临时凭据?

profile picture
专家
已提问 5 个月前31 查看次数
1 回答
0

【以下的回答经过翻译处理】 你可以从 https://<your_edge_gateway>/authenticate/ 获得边缘凭证。

一些Python代码:

  • host是你的边缘网关
  • userpassword是你的边缘用户的凭据。
  • auth_mech 取决于你的网关配置,可以是 linuxldap
def get_creds(host, user, password, auth_mech):
    url = f"https://{host}/authenticate/"
    
    data = { 
        "username": user, 
        "password": password, 
        "authMechanism": auth_mech
    }

    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
    }
    
    try:
        print(f'\nfetching API credentials from: "{url}"')
        
        # disable bandit warning for disabling SSL cert checks
        # because we us a self signed cert for demo purposes only
        request = requests.post(
            url, data=json.dumps(data),
            headers=headers, verify=False # nosec
        )
        
        if 'accessKeyId' in request.json() and \
            'secretAccessKey' in request.json() and \
            'sessionToken' in request.json():
            print("\nAPI credentials for the edge:")
            print(f"they expire {request.json()['sessionExpiryTime']}")
            print("-----------------------------")
            print(f"export AWS_ACCESS_KEY_ID={request.json()['accessKeyId']}")
            print(f"export AWS_SECRET_ACCESS_KEY={request.json()['secretAccessKey']}")
            print(f"export AWS_SESSION_TOKEN={request.json()['sessionToken']}")
            print('export AWS_REGION=Edge')
        else:
            print('ERROR: could not find credentials in response:')
            print(request.json())
    except Exception as error:
        print(f'ERROR: url: {url}: {error}')

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则