LoginSignup
14
14

More than 5 years have passed since last update.

[修正されたようです]API Gateway+Lambdaにエスケープされていない日本語リクエストを送るとエラーになる

Last updated at Posted at 2015-07-23

はじめに結論

現状、エスケープされていない日本語(マルチバイト文字)を含むPOSTリクエストをOpenで公開することは出来ないっぽい。

※2015年07月24日追記
エスケープしたら無事受信出来ました。
h141dev さん、ありがとうございます。
ただ、Backlog/GitHubのwebhookは引き続き受信できない。。。
エスケープされてないっぽい。

※2015年08月31日追記
認証エラー出なくなりました!
GitHubのwebhookとして登録してみたら、無事受信出来ました。
GitHubも、今見るとGit pushのwebhookに日本語は含まれてませんでした。前から出来てたのかもです。
ただ、Backlogのwebhookは引き続きNG。謎です。

※2015年09月15日追記
9/14のBacklog側のアップデートで修正されたらしく、
こちらで試してみたところ、テストは正常に通り、Lambdaのログにも出るようになりました。
uekikazuki さん、情報ありがとうございます!

やり方間違ってるよとか、いやいや出来たしとかあれば、コメント下さい。

試したこと

Lambdaを作成し、API endpointsからPOSTリクエストを作成しました。

作ったのは、 https://69i5gk43b2.execute-api.us-west-2.amazonaws.com/prod/lambda-webhook です。

成功するリクエスト

curl -X POST -d '{"test":""}' https://69i5gk43b2.execute-api.us-west-2.amazonaws.com/prod/lambda-webhook/

認証エラー(?)になるリクエスト

※2015年08月31日追記
エラーでは無くなりました!

curl -X POST -d '{"test":"あ"}' https://69i5gk43b2.execute-api.us-west-2.amazonaws.com/prod/lambda-webhook/

レスポンスはこんな感じ。

{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\n\nThe Canonical String for this request should have been\n'POST\n/2015-03-31/functions/arn%3Aaws%3Alambda%3Aus-west-2%3A913828629940%3Afunction%3Alambda-webhook/invocations\n\naccept:application/x-www-form-urlencoded\ncontent-type:application/x-www-form-urlencoded\nhost:lambda.us-west-2.amazonaws.com\nx-amz-content-sha256:df7afeb62fa766ccc8e5bcafd17fa0315c85c89a10321dbd3119fdc31861e328\nx-amz-date:20150723T144504Z\nx-amz-source-arn:arn:aws:execute-api:us-west-2:913828629940:69i5gk43b2/prod/POST/lambda-webhook\n\naccept;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-source-arn\nf0ed1af50c2207d0c88adc5255389797c3cb862d427561d625593d21a5fe92f8'\n\nThe String-to-Sign should have been\n'AWS4-HMAC-SHA256\n20150723T144504Z\n20150723/us-west-2/lambda/aws4_request\n4756a5793d6a6fb8d2eeb4e27e0df3f00e46741c5040fd652fae95ed5b0e2355'\n"}

成功するリクエスト2

curl -X POST -d '{"test":"\\u3053"}' https://69i5gk43b2.execute-api.us-west-2.amazonaws.com/prod/lambda-webhook/
14
14
10

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
14