share facebook facebook twitter menu hatena pocket slack

2018.12.11 TUE

Nuxt.js(v2.2.0)をAPI Gateway+AWS LambdaにNuxt.jsのgzip機能を有効化してデプロイしてみた

甲斐 甲

WRITTEN BY 甲斐 甲

Nuxt.jsをAWS Lambdaで動作させるのに参考にした記事それぞれで、Nuxt.jsのgzip機能を無効化するように実装されていますが、有効化されていたらどうなるのか試してみました。

この辺の記事です。

Nuxt.js on AWS Lambda with Serverless Framework – mya-ake com
https://mya-ake.com/posts/nuxtjs-on-aws-lambda/

Nuxt.js はデフォルトで gzip の機能が備わっています。 ありがたい機能ではあるのですが、このままだとブラウザで表示できなくなってしまいます。(Chrome では白い画面、 Firefox では Content-Encoding に問題があると表示されます。) 細かいところまで調べきれていないのですが、恐らく API Gateway にも gzip の機能が備わっているようです。 そのため、2重に gzip がかかった状態になってしまい、ブラウザがデコードできないのだと推測されます。

Explain why disable gzip · Issue #3 · jeehyukwon/nuxt-serverless
https://github.com/jeehyukwon/nuxt-serverless/issues/3

Turning on the gzip compression option causes errors to pass through the AWS API Gateway. I have not solved this problem yet, so I have disabled the gzip compression option.

Serverless-Side Rendering With AWS Lambda & NuxtJS
https://medium.com/@fernalvarez/serverless-side-rendering-with-aws-lambda-nuxtjs-b94d15782af5

“performance>gzip” is for performance configurations, since we don’t want gzip based request (not quite well supported by AWS Lambda), we just disable it.

結果

gzip機能を有効化したままデプロイして動作しました

現状は、Nuxt.js(v2.2.0)のgzip機能を無効化しなくてもAWS LambdaにデプロイしてAPI Gateway経由でアクセスできるようになっているみたいですね。Nuxt.jsのgzip機能を無効化しないと駄目だった状況を知らないのでなんともですが^^(2018/11/14時点)

検証

以下の記事で実装したソースを利用して検証してみます。

Nuxt.js(v2.2.0)+TypeScriptなアプリをAWS Lambda+αにデプロイしてみた
https://cloudpack.media/44795

> git clone https://github.com/kai-kou/nuxt-serverless.git
> npm install install

gzipを無効化したcompressor: { threshold: Infinity } 状態で実行してみます。

> cat nuxt.config.js
(略)
  router: {
    base: '/dev/'
  },
  render: {
    etag: false,
    // Disabled compression
    compressor: { threshold: Infinity },
  }
}

curl -v で詳細をみてみました。-H 'Accept-Encoding: gzip,deflate' を指定することでcurl でgzipが有効化確認できました。

Nginxのgzipが動いているか確認する方法 ~ クライアントサイド~
https://qiita.com/ukitazume/items/fff67c15da7b81cfa6ac

> npm run build
> npm run start

> curl -v -H 'Accept-Encoding: gzip,deflate' http://localhost:3000/dev/
(略)

* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /dev/ HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.54.0
> Accept: */*
> Accept-Encoding: gzip,deflate
>
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 1887
< Vary: Accept-Encoding
< Date: Wed, 14 Nov 2018 02:44:58 GMT
< Connection: keep-alive
<
<!doctype html>
<html data-n-head-ssr data-n-head="">
  <head>

はい。リクエスト時にAccept-Encoding: gzip,deflate を指定しても、gzip圧縮されないことが確認できました。

compressor で無効化しているのをコメントアウトして、デプロイし直します。

nuxt.config.js(一部抜粋)

(略)
  router: {
    base: '/dev/'
  },
  render: {
    etag: false,
    // Disabled compression
    // compressor: { threshold: Infinity },
  }

ローカルで確認

gzip無効化の設定を外すと、gzip圧縮されることが確認できました。

> npm run build
> npm run start


> curl -v -H 'Accept-Encoding: gzip,deflate' http://localhost:3000/dev/
(略)
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /dev/ HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.54.0
> Accept: */*
> Accept-Encoding: gzip,deflate
>
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< Vary: Accept-Encoding
< Content-Encoding: gzip
< Date: Wed, 14 Nov 2018 02:41:27 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
�UMo�0
      ��Whv���$v��n;
(略)

デプロイして確認

デプロイしてAPI Gateway経由で確認してみます。
(余談)検証の途中でわかったのですが、curl -I だとヘッダーしか返さないため、content-encoding: gzip がつかないみたいです。curl -i だとbodyも返すので、content-encoding: gzip がつきました^^

> npm run sls:deploy

> curl -i -H 'Accept-Encoding: gzip,deflate' https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/dev/

HTTP/2 200
content-type: text/html; charset=utf-8
content-length: 713
date: Wed, 14 Nov 2018 03:10:59 GMT
x-amzn-requestid: e94e34b9-e7ba-11e8-85ed-a9f080e8c709
content-encoding: gzip
x-amz-apigw-id: QVPKmHKQtjMFtYg=
vary: Accept-Encoding
x-powered-by: Express
x-amzn-trace-id: Root=1-5beb9243-755915c037d52100b400d740;Sampled=0
x-cache: Miss from cloudfront
via: 1.1 7eebbd2b614349709798674fc336acf2.cloudfront.net (CloudFront)
x-amz-cf-id: aHky4Z2VlCnno0kVCpzQ9JHL4LBVHuuvT22Rnv5stsgDUQXx-rIcNw==

�UMo�0
      ��Whv���$v��n;

問題なくアクセスできていますね。
ブラウザで確認してみてもコンテンツが正しく表示されました。

AWS Lambdaの関数を直接起動してみます。--payload パラメータの値はAWS マネジメントコンソールから引っ張ってきました。

aws lambda invoke \
--invocation-type RequestResponse \
--function-name nuxt-serverless-dev-nuxt-renderer \
--log-type Tail \
--payload '{
  "body": "eyJ0ZXN0IjoiYm9keSJ9",
  "resource": "/{proxy+}",
  "path": "/",
  "httpMethod": "GET",
  "isBase64Encoded": true,
  "queryStringParameters": {},
  "pathParameters": {
    "proxy": "/"
  },
  "stageVariables": {},
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "Accept-Encoding": "gzip, deflate, sdch",
    "Accept-Language": "en-US,en;q=0.8",
    "Cache-Control": "max-age=0",
    "CloudFront-Forwarded-Proto": "https",
    "CloudFront-Is-Desktop-Viewer": "true",
    "CloudFront-Is-Mobile-Viewer": "false",
    "CloudFront-Is-SmartTV-Viewer": "false",
    "CloudFront-Is-Tablet-Viewer": "false",
    "CloudFront-Viewer-Country": "US",
    "Host": "1234567890.execute-api.ap-northeast-1.amazonaws.com",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Custom User Agent String",
    "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
    "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
    "X-Forwarded-For": "127.0.0.1, 127.0.0.2",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https"
  },
  "requestContext": {
    "accountId": "123456789012",
    "resourceId": "123456",
    "stage": "prod",
    "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
    "requestTime": "09/Apr/2015:12:34:56 +0000",
    "requestTimeEpoch": 1428582896000,
    "identity": {
      "cognitoIdentityPoolId": null,
      "accountId": null,
      "cognitoIdentityId": null,
      "caller": null,
      "accessKey": null,
      "sourceIp": "127.0.0.1",
      "cognitoAuthenticationType": null,
      "cognitoAuthenticationProvider": null,
      "userArn": null,
      "userAgent": "Custom User Agent String",
      "user": null
    },
    "path": "/",
    "resourcePath": "/{proxy+}",
    "httpMethod": "POST",
    "apiId": "1234567890",
    "protocol": "HTTP/1.1"
  }
}' \
outputfile.txt

{
    "StatusCode": 200,
    "LogResult": "U1RBUlQgUmVxdWVzdElkOiBmYmRjNGYxNi1lN2JiLTExZTgtYWIwNS1iN2FjNzgwM2E2MjIgVmVyc2lvbjogJExBVEVTVApFTkQgUmVxdWVzdElkOiBmYmRjNGYxNi1lN2JiLTExZTgtYWIwNS1iN2FjNzgwM2E2MjIKUkVQT1JUIFJlcXVlc3RJZDogZmJkYzRmMTYtZTdiYi0xMWU4LWFiMDUtYjdhYzc4MDNhNjIyCUR1cmF0aW9uOiAyNy43OCBtcwlCaWxsZWQgRHVyYXRpb246IDEwMCBtcyAJTWVtb3J5IFNpemU6IDUxMiBNQglNYXggTWVtb3J5IFVzZWQ6IDEzOCBNQgkK",
    "ExecutedVersion": "$LATEST"
}


> cat outputfile.txt

{"isBase64Encoded":true,"statusCode":200,"headers":{"x-powered-by":"Express","content-type":"text/html; charset=utf-8","vary":"Accept-Encoding","content-encoding":"gzip"},"body":"H4sIAAAAAAAAA51VTW/bMAy991doAnaLv+IkdhzbwG47DD2sHTZgGAJZomOtimVIStqg6H+fZCddWjRdloss0XqPfKRJ5x+YpGbXAWrMWpRXuXsgRgzxWq8Bwjyt1fG5wLi8Qih3e7exW8ONgJd3jNoALj+DEHKErjcPBt2A2oISoDW6hXUniIE86JFlvgZD3sAj2hCjwRR4Y2ovxcHpmy1ZQ4G3HO47qYxFytZAa5H3nJmmYLDlFLz+MEK85YYT4WlKBBTRe7y9qeH2zEBTxTvDZXtw98L07PGUWudG8PbuLTcKRIE5dTyNgrrAgTbEcBrUZOvMvl0cviIaDjespgDvKXt8Z1dJGD6+sGxtNMF0CmkdhjFJYzKdp4xFUez/1hgRXeBBw7lMMJlSmrJ6PCWsIoTOJ9VlTBGLKhqNx4xVc5pUST1OIp/qA5XZCTiTic3pNK2tpnSSwiyFaD67UF06Y5QlbMIimEAdz5I4gctimtRRGMdJNU/GaURmCTD6bp56bt0AmP9J1dkMJ4X1rRwcejmvJNu90ez2DePb4YXuv2xPQctAwfMX7Fpk2TuzUbnLVBBttTqL1ym5UuDy2Ee578os/LhogK8ak427h0VF6N1KyU3LPCqFVFklrGUhO0K52WXhwhIHlnmgH/wJspObVx47sgKP2+gerL2JylP9iEI/9GMrPipR3pU3ZIf6eYWMRNeSgS0XSv0otOMCffp+g76QdcUIIi0bBtrYD/Ogs1hynG83Sg/1/bvPA/L64pAqt7qXe2XH64As760Uee8vl9ffftwul8XjoDmz06cmG2HwyJUl+/m4tuKs9AxfogQ//RqBUjbr7UaIkZs+kD3alGk73DLcpwo/jYbif93XPnOlf1rkwT7UfchIK3re+LESQJX/xJ9spjPxJ4fWmfiTA+YVvu8l10L2NxoMv9M/qDPo+F8HAAA="}

こちらも問題なし。

API GatewayのリソースをAWS-CLIから実行してログを確認してみます。

aws apigateway test-invoke-method \
--rest-api-id xxxxxxxxxx \
--resource-id xxxxxxxxxx \
--http-method GET \
--path-with-query-string '/' \
--headers '{"Accept-Encoding": "gzip,deflate"}'

{
    "status": 200,
    "body": "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0003�UMo�0\f��Wh\u0002v���$v\u001c��n;\f=�\u001d6`\u0018\u0002Y�c��eHJڠ��d']Z4]��,�z�|�I�\u001f��f�\u0001j�Z�W�{ F\f�Z�\u0001�<������B(w{��[Í��w��\u0000.?�\u0010r��7\u000f\u0006݀ڂ\u0012�5��u'��<�e�\u0006C��#�\u0010��\u0014xcj/���-YC��\u001c�;��E��@k�����`��\u0014��0B��\u0013�iJ\u0004\u0014�{������@S�;�e{p�����Z�F���-7\nD�9u<�����6�p\u001a�d�̾]\u001c�\"\u001a\u000e7��\u0000�){|gWI\u0018>��lm4�t\ni\u001d�1Ic2���EQ���\u0018\u0011]�AùL0�R��z<%�\"��'�eL\u0011�*\u001a�njUs�TI=N\"��\u0003��\t8����4���t��,�h>�P]:c�%l�\"�@\u001dϒ8��b��Q\u0018�I5O�iDf\t0�n�zn�\u0000��I��\f'���\u001c\u001cz9�$۽���\r����lOA�@��\u0017�Zd�;�Q��T\u0010m�:��)�R���G���,��h��\u001a����EE��J�M�<*�TY%�e!;B��e��\u0012\u0007�y�\u001f�\t���W\u001e;�\u0002���\u001e����S��B?�c+>*Qޕ7d��y��Dג�-\u0017J�(��\u0002}�~���u�\b\"-\u001b\u0006��\u000f�Xr�o7J\u000f����\u0003���*���{e��,�\u0014y�/���~�.���9�ӧ&\u001ba�ȕ%������\f_�\u0004?�\u001a�R6��F���>�=ڔi;�2ܧ\n?�����>s�Z��>�}�H+z���\u0012@��ğl�3�'�֙��\u0003�\u0015��%�B�7\u001a\f��?�3��_\u0007\u0000\u0000",
    "headers": {
        "X-Amzn-Trace-Id": "Root=1-5beb97b0-9fa2e94feaeabe07a1be900f;Sampled=0",
        "content-encoding": "gzip",
        "content-type": "text/html; charset=utf-8",
        "vary": "Accept-Encoding",
        "x-powered-by": "Express"
    },
    "multiValueHeaders": {
        "X-Amzn-Trace-Id": [
            "Root=1-5beb97b0-9fa2e94feaeabe07a1be900f;Sampled=0"
        ],
        "content-encoding": [
            "gzip"
        ],
        "content-type": [
            "text/html; charset=utf-8"
        ],
        "vary": [
            "Accept-Encoding"
        ],
        "x-powered-by": [
            "Express"
        ]
    },
    "log": "Execution log for request 24e4b1aa-e7be-11e8-9f95-b53002e38ff7\nWed Nov 14 03:34:08 UTC 2018 : Starting execution for request: 24e4b1aa-e7be-11e8-9f95-b53002e38ff7\nWed Nov 14 03:34:08 UTC 2018 : HTTP Method: GET, Resource Path: /\nWed Nov 14 03:34:08 UTC 2018 : Method request path: {}\nWed Nov 14 03:34:08 UTC 2018 : Method request query string: {}\nWed Nov 14 03:34:08 UTC 2018 : Method request headers: {Accept-Encoding=gzip,deflate}\nWed Nov 14 03:34:08 UTC 2018 : Method request body before transformations: \nWed Nov 14 03:34:08 UTC 2018 : Endpoint request URI: https://lambda.ap-northeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxxx:function:nuxt-serverless-dev-nuxt-renderer/invocations\nWed Nov 14 03:34:08 UTC 2018 : Endpoint request headers: {x-amzn-lambda-integration-tag=24e4b1aa-e7be-11e8-9f95-b53002e38ff7, Authorization=*****************************************************************************************************************************************************************************************************************************************************************************************************************************2911da, X-Amz-Date=20181114T033408Z, x-amzn-apigateway-api-id=xxxxxxxxxx, X-Amz-Source-Arn=arn:aws:execute-api:ap-northeast-1:xxxxxxxxxxxxx:xxxxxxxxxx/test-invoke-stage/GET/, Accept=application/json, User-Agent=AmazonAPIGateway_xxxxxxxxxx, X-Amz-Security-Token=FQoGZXIvYXdzEOz//////////wEaDCTYQzpetIWQ1eEffyLBA8lI/unpTeaxyAloEAc6gttD0iPTTCHNPsGfFRwvbY2OoxJjTLHzIOtxCgsUVRzOKVJxhhbOibRkhQBurVZp2SdWyt2gPNZ+HAlouupfS6YJeg6zgUjHMT87aewlxKi9P/560vYt6h0NO9CcED60DPcdbkU3/zBmpD/kDKFxI2B/gQqpz+eVXUfEiMGzxYgh3dM3n0wjjvGKCP1hx4bzXR3jAFUpfoZdtLzNFI8qCzEvdeyvNQsmhIWzHrIqTwUObhKRdPhJW8P3LL5WYqlhiPid9cwJj9qBb/ [TRUNCATED]\nWed Nov 14 03:34:08 UTC 2018 : Endpoint request body after transformations: {\"resource\":\"/\",\"path\":\"/\",\"httpMethod\":\"GET\",\"headers\":{\"Accept-Encoding\":\"gzip,deflate\"},\"multiValueHeaders\":{\"Accept-Encoding\":[\"gzip,deflate\"]},\"queryStringParameters\":null,\"multiValueQueryStringParameters\":null,\"pathParameters\":null,\"stageVariables\":null,\"requestContext\":{\"path\":\"/\",\"accountId\":\"xxxxxxxxxxxxx\",\"resourceId\":\"xxxxxxxxxx\",\"stage\":\"test-invoke-stage\",\"domainPrefix\":\"testPrefix\",\"requestId\":\"24e4b1aa-e7be-11e8-9f95-b53002e38ff7\",\"identity\":{\"cognitoIdentityPoolId\":null,\"cognitoIdentityId\":null,\"apiKey\":\"test-invoke-api-key\",\"cognitoAuthenticationType\":null,\"userArn\":\"arn:aws:iam::xxxxxxxxxxxxx:user/kai\",\"apiKeyId\":\"test-invoke-api-key-id\",\"userAgent\":\"aws-cli/1.16.27 Python/3.6.6 Darwin/17.7.0 botocore/1.12.17\",\"accountId\":\"xxxxxxxxxxxxx\",\"caller\":\"AIDAJSYPBDTBET63KDNTY\",\"sourceIp\":\"test-invoke-source-ip\",\"accessKey\":\"AKIAJANRYGXYRZBIMEXA\",\"cognitoAuthenticationProvider\":null,\"user\":\"AIDAJSYPBDTBET63KDNTY\"},\"domainName\":\"testPrefix.testDomainName\",\"re [TRUNCATED]\nWed Nov 14 03:34:08 UTC 2018 : Sending request to https://lambda.ap-northeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxxx:function:nuxt-serverless-dev-nuxt-renderer/invocations\nWed Nov 14 03:34:08 UTC 2018 : Received response. Integration latency: 322 ms\nWed Nov 14 03:34:08 UTC 2018 : Endpoint response body before transformations: {\"isBase64Encoded\":true,\"statusCode\":200,\"headers\":{\"x-powered-by\":\"Express\",\"content-type\":\"text/html; charset=utf-8\",\"vary\":\"Accept-Encoding\",\"content-encoding\":\"gzip\"},\"body\":\"H4sIAAAAAAAAA51VTW/bMAy991doAnaLv+IkdhzbwG47DD2sHTZgGAJZomOtimVIStqg6H+fZCddWjRdloss0XqPfKRJ5x+YpGbXAWrMWpRXuXsgRgzxWq8Bwjyt1fG5wLi8Qih3e7exW8ONgJd3jNoALj+DEHKErjcPBt2A2oISoDW6hXUniIE86JFlvgZD3sAj2hCjwRR4Y2ovxcHpmy1ZQ4G3HO47qYxFytZAa5H3nJmmYLDlFLz+MEK85YYT4WlKBBTRe7y9qeH2zEBTxTvDZXtw98L07PGUWudG8PbuLTcKRIE5dTyNgrrAgTbEcBrUZOvMvl0cviIaDjespgDvKXt8Z1dJGD6+sGxtNMF0CmkdhjFJYzKdp4xFUez/1hgRXeBBw7lMMJlSmrJ6PCWsIoTOJ9VlTBGLKhqNx4xVc5pUST1OIp/qA5XZCTiTic3pNK2tpnSSwiyFaD67UF06Y5QlbMIimEAdz5I4gctimtRRGMdJNU/GaURmCTD6bp56bt0AmP9J1dkMJ4X1rRwcejmvJNu90ez2DePb4YXuv2xPQctAwfMX7Fpk2TuzUbnLVBBttTqL1ym5UuDy2Ee578os/LhogK8ak427h0VF6N1KyU3LPCqFVFklrGUhO0K52WXhwhIHlnmgH/wJspObVx47sgKP2+gerL2JylP9iEI/9GMrPipR3pU3ZIf6eYWMRNeSgS0XSv0otOMCffp+g76QdcUIIi0bBtrYD/Ogs1hynG83Sg/1/bvPA/L64pAqt7qXe2XH64As760Uee8vl9ffft [TRUNCATED]\nWed Nov 14 03:34:08 UTC 2018 : Endpoint response headers: {Date=Wed, 14 Nov 2018 03:34:08 GMT, Content-Type=application/json, Content-Length=1133, Connection=keep-alive, x-amzn-RequestId=24e6ade6-e7be-11e8-8b99-0da3eca928e4, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5beb97b0-9fa2e94feaeabe07a1be900f;sampled=0}\nWed Nov 14 03:34:08 UTC 2018 : Method response body after transformations: [Binary Data]\nWed Nov 14 03:34:08 UTC 2018 : Method response headers: {x-powered-by=Express, content-type=text/html; charset=utf-8, vary=Accept-Encoding, content-encoding=gzip, X-Amzn-Trace-Id=Root=1-5beb97b0-9fa2e94feaeabe07a1be900f;Sampled=0}\nWed Nov 14 03:34:08 UTC 2018 : Successfully completed execution\nWed Nov 14 03:34:08 UTC 2018 : Method completed with status: 200\n",
    "latency": 331
}

長くなったので、ログを抜粋します。

Execution log for request 24e4b1aa-e7be-11e8-9f95-b53002e38ff7
Wed Nov 14 03:34:08 UTC 2018 : Starting execution for request: 24e4b1aa-e7be-11e8-9f95-b53002e38ff7
Wed Nov 14 03:34:08 UTC 2018 : HTTP Method: GET, Resource Path: /
Wed Nov 14 03:34:08 UTC 2018 : Method request path: {}
Wed Nov 14 03:34:08 UTC 2018 : Method request query string: {}
Wed Nov 14 03:34:08 UTC 2018 : Method request headers: {Accept-Encoding=gzip,deflate}
Wed Nov 14 03:34:08 UTC 2018 : Method request body before transformations: 
Wed Nov 14 03:34:08 UTC 2018 : Endpoint request URI: https://lambda.ap-northeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxxx:function:nuxt-serverless-dev-nuxt-renderer/invocations
Wed Nov 14 03:34:08 UTC 2018 : Endpoint request headers: {x-amzn-lambda-integration-tag=24e4b1aa-e7be-11e8-9f95-b53002e38ff7, Authorization=*****************************************************************************************************************************************************************************************************************************************************************************************************************************2911da, X-Amz-Date=20181114T033408Z, x-amzn-apigateway-api-id=xxxxxxxxxx, X-Amz-Source-Arn=arn:aws:execute-api:ap-northeast-1:xxxxxxxxxxxxx:xxxxxxxxxx/test-invoke-stage/GET/, Accept=application/json, User-Agent=AmazonAPIGateway_xxxxxxxxxx, X-Amz-Security-Token=FQoGZXIvYXdzEOz//////////wEaDCTYQzpetIWQ1eEffyLBA8lI/unpTeaxyAloEAc6gttD0iPTTCHNPsGfFRwvbY2OoxJjTLHzIOtxCgsUVRzOKVJxhhbOibRkhQBurVZp2SdWyt2gPNZ+HAlouupfS6YJeg6zgUjHMT87aewlxKi9P/560vYt6h0NO9CcED60DPcdbkU3/zBmpD/kDKFxI2B/gQqpz+eVXUfEiMGzxYgh3dM3n0wjjvGKCP1hx4bzXR3jAFUpfoZdtLzNFI8qCzEvdeyvNQsmhIWzHrIqTwUObhKRdPhJW8P3LL5WYqlhiPid9cwJj9qBb/ [TRUNCATED]
Wed Nov 14 03:34:08 UTC 2018 : Endpoint request body after transformations: {\"resource\":\"/\",\"path\":\"/\",\"httpMethod\":\"GET\",\"headers\":{\"Accept-Encoding\":\"gzip,deflate\"},\"multiValueHeaders\":{\"Accept-Encoding\":[\"gzip,deflate\"]},\"queryStringParameters\":null,\"multiValueQueryStringParameters\":null,\"pathParameters\":null,\"stageVariables\":null,\"requestContext\":{\"path\":\"/\",\"accountId\":\"xxxxxxxxxxxxx\",\"resourceId\":\"xxxxxxxxxx\",\"stage\":\"test-invoke-stage\",\"domainPrefix\":\"testPrefix\",\"requestId\":\"24e4b1aa-e7be-11e8-9f95-b53002e38ff7\",\"identity\":{\"cognitoIdentityPoolId\":null,\"cognitoIdentityId\":null,\"apiKey\":\"test-invoke-api-key\",\"cognitoAuthenticationType\":null,\"userArn\":\"arn:aws:iam::xxxxxxxxxxxxx:user/kai\",\"apiKeyId\":\"test-invoke-api-key-id\",\"userAgent\":\"aws-cli/1.16.27 Python/3.6.6 Darwin/17.7.0 botocore/1.12.17\",\"accountId\":\"xxxxxxxxxxxxx\",\"caller\":\"AIDAJSYPBDTBET63KDNTY\",\"sourceIp\":\"test-invoke-source-ip\",\"accessKey\":\"AKIAJANRYGXYRZBIMEXA\",\"cognitoAuthenticationProvider\":null,\"user\":\"AIDAJSYPBDTBET63KDNTY\"},\"domainName\":\"testPrefix.testDomainName\",\"re [TRUNCATED]
Wed Nov 14 03:34:08 UTC 2018 : Sending request to https://lambda.ap-northeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxxx:function:nuxt-serverless-dev-nuxt-renderer/invocations
Wed Nov 14 03:34:08 UTC 2018 : Received response. Integration latency: 322 ms
Wed Nov 14 03:34:08 UTC 2018 : Endpoint response body before transformations: {\"isBase64Encoded\":true,\"statusCode\":200,\"headers\":{\"x-powered-by\":\"Express\",\"content-type\":\"text/html; charset=utf-8\",\"vary\":\"Accept-Encoding\",\"content-encoding\":\"gzip\"},\"body\":\"H4sIAAAAAAAAA51VTW/bMAy991doAnaLv+IkdhzbwG47DD2sHTZgGAJZomOtimVIStqg6H+fZCddWjRdloss0XqPfKRJ5x+YpGbXAWrMWpRXuXsgRgzxWq8Bwjyt1fG5wLi8Qih3e7exW8ONgJd3jNoALj+DEHKErjcPBt2A2oISoDW6hXUniIE86JFlvgZD3sAj2hCjwRR4Y2ovxcHpmy1ZQ4G3HO47qYxFytZAa5H3nJmmYLDlFLz+MEK85YYT4WlKBBTRe7y9qeH2zEBTxTvDZXtw98L07PGUWudG8PbuLTcKRIE5dTyNgrrAgTbEcBrUZOvMvl0cviIaDjespgDvKXt8Z1dJGD6+sGxtNMF0CmkdhjFJYzKdp4xFUez/1hgRXeBBw7lMMJlSmrJ6PCWsIoTOJ9VlTBGLKhqNx4xVc5pUST1OIp/qA5XZCTiTic3pNK2tpnSSwiyFaD67UF06Y5QlbMIimEAdz5I4gctimtRRGMdJNU/GaURmCTD6bp56bt0AmP9J1dkMJ4X1rRwcejmvJNu90ez2DePb4YXuv2xPQctAwfMX7Fpk2TuzUbnLVBBttTqL1ym5UuDy2Ee578os/LhogK8ak427h0VF6N1KyU3LPCqFVFklrGUhO0K52WXhwhIHlnmgH/wJspObVx47sgKP2+gerL2JylP9iEI/9GMrPipR3pU3ZIf6eYWMRNeSgS0XSv0otOMCffp+g76QdcUIIi0bBtrYD/Ogs1hynG83Sg/1/bvPA/L64pAqt7qXe2XH64As760Uee8vl9ffft [TRUNCATED
nWed Nov 14 03:34:08 UTC 2018 : Endpoint response headers: {Date=Wed, 14 Nov 2018 03:34:08 GMT, Content-Type=application/json, Content-Length=1133, Connection=keep-alive, x-amzn-RequestId=24e6ade6-e7be-11e8-8b99-0da3eca928e4, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5beb97b0-9fa2e94feaeabe07a1be900f;sampled=0}
Wed Nov 14 03:34:08 UTC 2018 : Method response body after transformations: [Binary Data]
Wed Nov 14 03:34:08 UTC 2018 : Method response headers: {x-powered-by=Express, content-type=text/html; charset=utf-8, vary=Accept-Encoding, content-encoding=gzip, X-Amzn-Trace-Id=Root=1-5beb97b0-9fa2e94feaeabe07a1be900f;Sampled=0}
Wed Nov 14 03:34:08 UTC 2018 : Successfully completed execution
Wed Nov 14 03:34:08 UTC 2018 : Method completed with status: 200

どうやら、Nuxt.jsのgzip機能を有効化したままでも問題ないみたいです。

まとめ

現状は、Nuxt.js(v2.2.0)のgzip機能を無効化しなくてもAWS LambdaにデプロイしてAPI Gateway経由でアクセスできるようになっているみたいですね。Nuxt.jsのgzip機能を無効化しないと駄目だった状況を知らないのでなんともですが^^
(2018/11/14時点)

参考

Nuxt.js on AWS Lambda with Serverless Framework – mya-ake com
https://mya-ake.com/posts/nuxtjs-on-aws-lambda/

Explain why disable gzip · Issue #3 · jeehyukwon/nuxt-serverless
https://github.com/jeehyukwon/nuxt-serverless/issues/3

Serverless-Side Rendering With AWS Lambda & NuxtJS
https://medium.com/@fernalvarez/serverless-side-rendering-with-aws-lambda-nuxtjs-b94d15782af5

curlでgzipが効いているかどうか確認する | ハックノート
https://hacknote.jp/archives/13627/

Nginxのgzipが動いているか確認する方法 ~ クライアントサイド~
https://qiita.com/ukitazume/items/fff67c15da7b81cfa6ac

ステップ 3: Lambda 関数を呼び出す (AWS CLI) – AWS Lambda
https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/with-userapp-walkthrough-custom-events-invoke.html

test-invoke-method — AWS CLI 1.16.54 Command Reference
https://docs.aws.amazon.com/cli/latest/reference/apigateway/test-invoke-method.html

Nuxt.js(v2.2.0)+TypeScriptなアプリをAWS Lambda+αにデプロイしてみた
https://cloudpack.media/44795

元記事はこちら

Nuxt.js(v2.2.0)をAPI Gateway+AWS LambdaにNuxt.jsのgzip機能を有効化してデプロイしてみた

甲斐 甲

甲斐 甲

2018/7にJOIN。 最近の好みはサーバレスです。なんでもとりあえず試します。

cloudpack

cloudpackは、Amazon EC2やAmazon S3をはじめとするAWSの各種プロダクトを利用する際の、導入・設計から運用保守を含んだフルマネージドのサービスを提供し、バックアップや24時間365日の監視/障害対応、技術的な問い合わせに対するサポートなどを行っております。
AWS上のインフラ構築およびAWSを活用したシステム開発など、案件のご相談はcloudpack.jpよりご連絡ください。