我尝试使用boto3验证我在console 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}}我不能理解如果documentation和api_key是create resent会发生什么
发布于 2020-04-29 08:20:57
根据注释,错误发生是因为get_api_key需要的是API密钥标识符,而不是密钥的值:
需要ApiKey资源的标识符。
发布于 2020-04-29 21:15:18
@Marcin我这样做是为了不增加lambda的计算复杂度。
effect= "Deny"
if result["user"]:
effect="Allow"
policy = {
"principalId": "user",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": effect,
"Resource": event["methodArn"]
}
]
},
"usageIdentifierKey": result["apikey"]
}
return policyhttps://stackoverflow.com/questions/61491938
复制相似问题