2016-09-27 11 views
0

私はJavaでLambda - > ApiGatewayを使用していますが、ステージ変数が必要です。AWS ApiGatewayリクエストテンプレートパススルー

私は統合要求としてアマゾンが提供するデフォルトのテンプレート、使用

## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html 
## This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload 
#set($allParams = $input.params()) 
{ 
"body-json" : $input.json('$'), 
"params" : { 
#foreach($type in $allParams.keySet()) 
    #set($params = $allParams.get($type)) 
"$type" : { 
    #foreach($paramName in $params.keySet()) 
    "$paramName" : "$util.escapeJavaScript($params.get($paramName))" 
     #if($foreach.hasNext),#end 
    #end 
} 
    #if($foreach.hasNext),#end 
#end 
}, 
"stage-variables" : { 
#foreach($key in $stageVariables.keySet()) 
"$key" : "$util.escapeJavaScript($stageVariables.get($key))" 
    #if($foreach.hasNext),#end 
#end 
}, 
"context" : { 
    "account-id" : "$context.identity.accountId", 
    "api-id" : "$context.apiId", 
    "api-key" : "$context.identity.apiKey", 
    "authorizer-principal-id" : "$context.authorizer.principalId", 
    "caller" : "$context.identity.caller", 
    "cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider", 
    "cognito-authentication-type" : "$context.identity.cognitoAuthenticationType", 
    "cognito-identity-id" : "$context.identity.cognitoIdentityId", 
    "cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId", 
    "http-method" : "$context.httpMethod", 
    "stage" : "$context.stage", 
    "source-ip" : "$context.identity.sourceIp", 
    "user" : "$context.identity.user", 
    "user-agent" : "$context.identity.userAgent", 
    "user-arn" : "$context.identity.userArn", 
    "request-id" : "$context.requestId", 
    "resource-id" : "$context.resourceId", 
    "resource-path" : "$context.resourcePath" 
    } 
} 

私は新しいAWS SDK(今ジャクソンJSONの解析を含みます)に切り替えて、テンプレートデータを解析するために、このクラスを使用します。

https://github.com/ingenieux/lambada/blob/master/lambada-runtime/src/main/java/io/ingenieux/lambada/runtime/model/PassthroughRequest.java

私の問題は今、私はUnittestを作成し、その例を解析させました。すべてがうまくいきます。しかし、AWSで実行される場合、ステージ変数は満たされません。

テンプレートの「stage-variables」を「stageVariables」に変更してJavaクラスを調整すると、正しい値が入力されます。

なぜプロパティ名の「 - 」で機能しないのですか?

おかげ

答えて

0

私はあなたが提供するテンプレートクラスのソースを見てから、問題を診断することができませんでしだ。

APIでCloudWatchログを有効にしてテストを実行できますか?これにより、ラムダに渡されているAPIゲートウェイが表示され、問題がテンプレートまたはJavaクラスにあるかどうかを判断できます。

関連する問題