リクエスト データのマッピングについて多くの質問があることは承知していますが、どれも役に立ちませんでした。だから、私が達成しようとしているのは、ラムダにマップされた API エンドポイントです。バケットが 404 をトリガーすると、そのエンドポイントへのリクエストが転送され、パラメーターが /{image_name}/{width}/{height} のようなリクエスト パスを介してラムダに渡されます。私のラムダのコードは単に呼び出しますcontext.succeed(event, context);
メソッド リクエスト構成では、リクエスト パスのパラメータが自動的に作成されました。
統合リクエストで、次の 3 つのマッピング テンプレートを作成しました。plain/text、plain/html、application/json の定義は以下と同じです。
#set($inputRoot = $input.path('$'))
{
"name": $input.params('name'),
"width" : $input.params('width'),
"height" : $input.params('height'),
"params": $input.params(),
"resourcePath": $context.resourcePath,
}
クロムレストクライアントから呼び出すと、次のようになります。
コンソールからテストを呼び出すと、次の応答が返さ
{"Type":"User","message":"Could not parse request body into json."}
れます。curl を呼び出したとき、または単にブラウザで URL を開いたときと同じ応答が得られます。
しかし、コンソールのテスト コールのログには次のように表示されます。
Execution log for request test-request
Tue Sep 08 09:10:20 UTC 2015 : Starting execution for request: test-invoke-request
Tue Sep 08 09:10:20 UTC 2015 : API Key: test-invoke-api-key
Tue Sep 08 09:10:20 UTC 2015 : Method request path: {name=name, width=100, height=100}
Tue Sep 08 09:10:20 UTC 2015 : Method request query string: {}
Tue Sep 08 09:10:20 UTC 2015 : Method request headers: {}
Tue Sep 08 09:10:20 UTC 2015 : Method request body before transformations: null
Tue Sep 08 09:10:20 UTC 2015 : Endpoint request URI: <endpoint>:function:Magic/invocations
Tue Sep 08 09:10:20 UTC 2015 : Endpoint request headers: {
Authorization=<authorization>
Credential=<credential>,
SignedHeaders=accept;content-type;host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-source-arn,
Signature=<signature>,
X-Amz-Date=20150908T091020Z,
X-Amz-Source-Arn=<ARN>/null/GET/image/{name}/{width}/{height},
Accept=application/json,
User-Agent=AmazonAPIGateway_ebkkwbbpo0,
Host=lambda.us-east-1.amazonaws.com,
X-Amz-Content-Sha256=<key>,
Content-Type=application/json
}
Tue Sep 08 09:10:20 UTC 2015 : Endpoint request body after transformations: {
"name": name,
"width" : 100,
"height" : 100,
"params": {path={name=name, width=100, height=100}, querystring={}, header={}},
"resourcePath": /image/{name}/{width}/{height},
}
Tue Sep 08 09:10:20 UTC 2015 : Endpoint response body before transformations: {"Type":"User","message":"Could not parse request body into json."}
Tue Sep 08 09:10:20 UTC 2015 : Endpoint response headers: {
x-amzn-ErrorType=InvalidRequestContentException:http://internal.amazon.com/coral/com.amazonaws.awsgirapi/,
x-amzn-RequestId=<RequestId>,
Connection=keep-alive,
Content-Length=68,
Date=Tue, 08 Sep 2015 09:10:20 GMT,
Content-Type=application/json}
Tue Sep 08 09:10:20 UTC 2015 : Method response body after transformations: {"Type":"User","message":"Could not parse request body into json."}
Tue Sep 08 09:10:20 UTC 2015 : Method response headers: {Content-Type=application/json}
Tue Sep 08 09:10:20 UTC 2015 : Successfully completed execution
ある時点でわかるように、URL パスは正しく解析されますが、何が問題なのかわかりません。また、X-Amz-Source-Arn のパスに null 値がある理由もわかりません。
ありがとうございました。