首页 > 解决方案 > 指定的 aws api gateway boto3 API 密钥标识符无效

问题描述

我尝试使用 boto3 验证我在控制台 api 网关上创建的 api_key,这是我的代码:

def apikey_validate(api_key):
    try:
        client = boto3.client('apigateway')
        response = client.get_api_key(
        apiKey=api_key,
        includeValue = False
        )
        return response
    except ClientError as e:
        return e.response

但回应是这样的:

"Error":{"Message":"Invalid API Key identifier specified","Code":"NotFoundException"},
"ResponseMetadata":{"RequestId":"d7dbf2c6-7bb6-4747-929a-ec737c8fadc7",
"HTTPStatusCode":404,
"HTTPHeaders":{"date":"Tue, 28 Apr 2020 23:40:04 GMT","content-type":"application/json",
"content-length":"51",
"connection":"keep-alive",
"x-amzn-requestid":"d7dbf2c6-7bb6-4747-929a-ec737c8fadc7","x-amzn-errortype":"NotFoundException","x-amz-apigw-id":"LuLBPKDbIAMEdrA="},
"RetryAttempts":0}}

而且我不明白如果像文档一样会发生什么,并且 api_key 是重新发送的

标签: pythonaws-api-gatewayboto3

解决方案


根据评论,发生错误是因为get_api_key需要 API 密钥标识符,而不是密钥的值:

【必填】ApiKey 资源的标识


推荐阅读