2024-09-26 22:52:25 发布
网友
我正在为awsapi网关编写自己的AWS自定义Lambda授权程序。 我需要允许以下URL:
/api/v1/get?detail=yes
但在相同的策略中,我还想拒绝以下URL
/api/v1/get?detail=no
我已经查看了策略条件,但找不到将URL参数detail放在条件中的方法
detail
有人知道怎么做的细节吗
您可以这样获得URL参数:event["queryStringParameters"]['detail']
event["queryStringParameters"]['detail']
所以代码应该是这样的:
def auth(event, context): detail = event["queryStringParameters"]['detail'] if detail == 'yes': return { 'principalId': principal_id, 'policyDocument': { 'Version': '2012-10-17', 'Statement': [ { "Action": "execute-api:Invoke", "Effect": effect, "Resource": resource } ] } } else: raise Exception('Unauthorized')
您可以这样获得URL参数:
event["queryStringParameters"]['detail']
所以代码应该是这样的:
相关问题 更多 >
编程相关推荐