AWS自定义Lambda Authorizer:基于具有相同前导URL的URL参数的Allow和Deny

2024-09-26 22:52:25 发布

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

我正在为awsapi网关编写自己的AWS自定义Lambda授权程序。 我需要允许以下URL:

/api/v1/get?detail=yes

但在相同的策略中,我还想拒绝以下URL

/api/v1/get?detail=no

我已经查看了策略条件,但找不到将URL参数detail放在条件中的方法

有人知道怎么做的细节吗


Tags: lambdano程序awsapiurl网关参数
1条回答
网友
1楼 · 发布于 2024-09-26 22:52:25

您可以这样获得URL参数: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')

相关问题 更多 >

    热门问题