如何使用Python调用带有Cognito认证的AppSync变更?

2024-06-01 04:20:26 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以使用Python调用带有Cognito身份验证的AppSync变异?怎样?在

我尝试使用boto3,但是我没有找到执行graphql操作的方法。在

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appsync.html


Tags: 方法httpscom身份验证apidocumentationboto3latest
1条回答
网友
1楼 · 发布于 2024-06-01 04:20:26

您可以将API身份验证模式转换为“API密钥”,并使用http调用AppSync变体。在

例如。在

import requests
import json

APPSYNC_API_KEY = 'da2-xxxxxxxxxxxxx'
APPSYNC_API_ENDPOINT_URL = 'https://xxxxxxxxxxxxx.appsync-api.us-west-2.amazonaws.com/graphql'

headers = {
    'Content-Type': "application/graphql",
    'x-api-key': APPSYNC_API_KEY,
    'cache-control': "no-cache",
}

def execute_gql(query):
    payload_obj = {"query": query}
    payload = json.dumps(payload_obj)
    response = requests.request("POST", APPSYNC_API_ENDPOINT_URL, data=payload, headers=headers)
    return response

假设您有一个名为Items的模型,您可以轻松地进行如下查询:

^{pr2}$

只需将字符串替换为变异操作。在

相关问题 更多 >