1

Ich versuche, die API-Aufrufe obwohl AWS API-Gateway Custom authorizer,
die im Grunde Lambda-Funktion ein Brauch ist zu genehmigen, die von folgenden Format- im folgenden Header nimmtAWS API-Gateway Benutzerdefinierte Authorizer Lambda

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

und erwartet eine Antwort in folgendem Format -

{ 
    "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/*" 
     ] 
     } 
    ] 
    } 
} 

ich bin in der Lage, die interne Logik mit dem autho zu tun rizationToken und validieren, ob die Funktion in einem „Zulassen“ oder „Verweigern“ Politik meine Anfrage Protokolle,
Aber ich bin immer ein Parsing-Fehler, wenn ich versuchte, die Authorizer von der Konsole zu testen,
Es folgen reagieren sollte -

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 

ich bin mit Java auf der Funktion Lambda und ich habe bauen und gab die Politik aa Pojo-Klasse (Setter-Getter-Klasse)
Nach der Lambda-Antwort verschönernde meine Politik wie folgt aussieht -

{ 
    "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" 
     }] 
    } 
} 

Ich wundere mich, warum es nicht in der Lage ist, meine Antwort zu analysieren?
Wie pro rate ich versucht, die Antwort IAM-Politik, verwendet
I @SerializedName von com.google.gson.annotations.SerializedName Import zu nutzen und konnte die folgende Ausgabe erhalten -

{ 
    "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/"] 
     }] 
    } 
} 

Aber es sieht aus wie etwas seltsam geschieht dazwischen Meine Lambda-Antwort und das API-Gateway,
Die Variablen werden intern irgendwo tiefer geholt,
Und ich habe immer noch die gleichen Parsing Fehler,
Konnte es eine Antwort akzeptieren i n ein anderes Format? String hat auch nicht funktioniert.

Was sollte ich noch versuchen? Ist mein Richtlinienformat falsch?
bekam ich zwei verschiedene Richtlinienformate von diesen Seiten -
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/

Antwort

4

Ihre Politik Attribute richtige Aktivierung benötigen. Statt:

{ 
    "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" 
     }] 
    } 
} 

werden sollten:

{ 
    "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" 
     }] 
    } 
} 

Es könnte aber auch nutzen "PrincipalId", um die Dinge konsistent.

Verwandte Themen