Receiving temporary credentials for AWS Sitewise Edge REST API

0

How can I receive the temporary credentials for AWS Sitewise Edge REST API without OpsHub UI?

질문됨 일 년 전241회 조회
1개 답변
3
수락된 답변

Hi,

you can get Edge credentials from https://<your_edge_gateway>/authenticate/.

Some Python code:

  • host is you edge gateway
  • user and password are credentials for your edge user.
  • auth_mech can be linux or ldap depending on your gateway configuration
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}')

Cheers,
Philipp

AWS
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인