1

私はAWS API GatewayのカスタムオーソしかしAPI呼び出しを承認しようとしています、基本的にformat-AWS API Gatewayのカスタムオーソラムダ

{ 
    "authorizationToken": "0c34ba00bde34200b383abe22bcfef96", 
    "methodArn": "arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/null/GET/", 
    "type": "TOKEN" 
} 

を次の次のヘッダーに取りカスタムラムダ関数である
次の形式で応答を期待する -

{ 
    "principalId": "xxxxxxx", // the principal user identification associated with the token send by the client 
    "policyDocument": { // example policy shown below, but this value is any valid policy 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
     "Effect": "Allow", 
     "Action": [ 
      "execute-api:Invoke" 
     ], 
     "Resource": [ 
      "arn:aws:execute-api:us-east-1:xxxxxxxxxxxx:xxxxxxxx:/test/*/mydemoresource/*" 
     ] 
     } 
    ] 
    } 
} 

私はauthoと内部ロジックを行うことができますよrizationToken、次の

、関数は「許可」または「拒否」ポリシー
に応じるべきかどうかを検証するしかし、私は、コンソールからオーソをテストしようとしたとき、私は解析エラーを取得していますが、私のリクエストのログです -

Execution log for request test-request 
Thu Jun 29 11:48:10 UTC 2017 : Starting authorizer: 1o3dvk for request: test-request 
Thu Jun 29 11:48:10 UTC 2017 : Incoming identity: **************************cfef96 
Thu Jun 29 11:48:10 UTC 2017 : Endpoint request URI: https://lambda.ap-southeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-southeast-1:855399270504:function:um_guestSessionAuthoriser/invocations 
Thu Jun 29 11:48:10 UTC 2017 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=*********************************************************************************************************************************************************************************************************************************************************************************************************************************************751e60, X-Amz-Date=20170629T114810Z, x-amzn-apigateway-api-id=z6t3cv0z4m, X-Amz-Source-Arn=arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/authorizers/1o3dvk, Accept=application/json, User-Agent=AmazonAPIGateway_z6t3cv0z4m, X-Amz-Security-Token=FQoDYXdzEHQaDOcIbaPscYGsl1wF4iLBAxzOTpZlR2r3AO3g96xwhRuQjEhU9OjOaRieBWQPeosNqv53aGKnBTT2CmkrVzHo3UqOdT1eakuS7tAXAbEcUIHVheWpBnvxqTkaPcknRL7QE79RSqVeryoXo2R1Kmk0Q9Iq+JGFlOJYQQJqvY/hcUg189xqbpTGrhZjcA+pjuSp+M9D97Kce0VP0e3peu/YvON0eGvUlj59MAJAwGVPIzplMKTDFrFg5NKEj79RSxNrNE8y4bAebOwlD8xLv649Zny7++xlMBBwHqMNHu3K9lFXSnKY9DHf6kvezZmpoFB2uu8WbrpInH0eQ/bIAd [TRUNCATED] 
Thu Jun 29 11:48:10 UTC 2017 : Endpoint request body after transformations: {"type":"TOKEN","methodArn":"arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/null/GET/","authorizationToken":"0c34ba00bde34200b383abe22bcfef96"} 
Thu Jun 29 11:48:10 UTC 2017 : Sending request to https://lambda.ap-southeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-southeast-1:855399270504:function:um_guestSessionAuthoriser/invocations 
Thu Jun 29 11:48:21 UTC 2017 : Authorizer result body before parsing: {"principalId":"user","policyDocument":{"version":"2012-10-17","statement":[{"resource":"arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/null/GET/","action":"execute-api:Invoke","effect":"Allow"}]}} 
Thu Jun 29 11:48:21 UTC 2017 : Execution failed due to configuration error: Could not parse policy: {"version":"2012-10-17","statement":[{"resource":"arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/null/GET/","action":"execute-api:Invoke","effect":"Allow"}]} 
Thu Jun 29 11:48:21 UTC 2017 : AuthorizerConfigurationException 

私はラムダ関数にJavaを使用していると私は構築し、次のように私のポリシーに見えるラムダ反応を美化した後のaa POJOクラス(セッターゲッタークラス)
を使用してポリシーを返した -

なぜ私の応答を解析できないのでしょうか? 私は応答IAMポリシーを活用しようとしたアドバイスを1として

私はcom.google.gson.annotations.SerializedName輸入の@SerializedNameを使用し、以下のような出力を得ることができました -

{ 
    "principalId": "user", 
    "policyDocument": { 
     "version": "2012-10-17", 
     "statement": [{ 
      "effect": "Deny", 
      "action": ["execute-api:Invoke"], 
      "resource": ["arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/null/GET/"] 
     }] 
    } 
} 

をしかし、それは間で起こっている奇妙なもののように見えます私のラムダ応答とAPIゲートウェイ
変数は内部的にどこか低いケースに入っています
そして、私はまだ同じ解析エラーがあります
応答iを受け入れることができますか?他の形式ですか?ストリングも機能しませんでした。

他に何を試してください。私のポリシー形式は間違っていますか?
私はこれらのサイトからの二つの異なるポリシー形式を持って -
1. http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html
2. https://aws.amazon.com/blogs/compute/introducing-custom-authorizers-in-amazon-api-gateway/

答えて

4

あなたのポリシー属性が適切な資本化を必要としています。代わりに:

{ 
    "principalId": "user", 
    "policyDocument": { 
     "version": "2012-10-17", 
     "statement": [{ 
      "resource": "arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/null/GET/", 
      "action": "execute-api:Invoke", 
      "effect": "Allow" 
     }] 
    } 
} 

は次のようになります。

{ 
    "principalId": "user", 
    "PolicyDocument": { 
     "Version": "2012-10-17", 
     "Statement": [{ 
      "Resource": "arn:aws:execute-api:ap-southeast-1:855399270504:z6t3cv0z4m/null/GET/", 
      "Action": "execute-api:Invoke", 
      "Effect": "Allow" 
     }] 
    } 
} 

にも一貫性のあるものを維持するために、 "PrincipalId" を使用する場合があります。

関連する問題