如何在AWS lambda中创建自定义授权器,其中考虑了API网关中自定义域名的基本路径映射?

时间:2017-07-12 12:09:08

标签: aws-lambda aws-api-gateway custom-authentication base-path

似乎授权者没有收到任何与基本路径相关的信息。即使您在上下文中传递它,似乎也无法将其添加到策略中。

例如: domain.com/basepath1**/resource/resourceID** domain.com/basepath2 ** /资源/ RESOURCEID **

现行政策声明:

[{ 动作:'execute-api:Invoke', 效果:'允许', 资源:'arn:aws:execute-api:us-east-1:accountID:apiID / dev / GET ** / resource / resourceID **' }]

1 个答案:

答案 0 :(得分:0)

API Gateway最近发布了一些针对客户授权人的增强功能,包括一个新的REQUEST类型授权程序,它从传入的请求中传递了更多信息。虽然未明确调出基本路径,但它可能存在于其中一个路径参数中。

{
    "type": "REQUEST",
    "methodArn": "arn:aws:execute-api:us-east-1:123456789012:s4x3opwd6i/test/GET/request",
    "resource": "/request",
    "path": "/request",
    "httpMethod": "GET",
    "headers": {
        "X-AMZ-Date": "20170718T062915Z",
        "Accept": "*/*",
        "HeaderAuth1": "headerValue1",
        "CloudFront-Viewer-Country": "US",
        "CloudFront-Forwarded-Proto": "https",
        "CloudFront-Is-Tablet-Viewer": "false",
        "CloudFront-Is-Mobile-Viewer": "false",
        "User-Agent": "...",
        "X-Forwarded-Proto": "https",
        "CloudFront-Is-SmartTV-Viewer": "false",
        "Host": "....execute-api.us-east-1.amazonaws.com",
        "Accept-Encoding": "gzip, deflate",
        "X-Forwarded-Port": "443",
        "X-Amzn-Trace-Id": "...",
        "Via": "...cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "...",
        "X-Forwarded-For": "..., ...",
        "Postman-Token": "...",
        "cache-control": "no-cache",
        "CloudFront-Is-Desktop-Viewer": "true",
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "queryStringParameters": {
        "QueryString1": "queryValue1"
    },
    "pathParameters": {},
    "stageVariables": {
        "StageVar1": "stageValue1"
    },
    "requestContext": {
        "path": "/request",
        "accountId": "123456789012",
        "resourceId": "05c7jb",
        "stage": "test",
        "requestId": "...",
        "identity": {
            "apiKey": "...",
            "sourceIp": "..."
        },
        "resourcePath": "/request",
        "httpMethod": "GET",
        "apiId": "s4x3opwd6i"
    }
}

来自documentation here