Amazon CloudWatch Events で AWS Lambda を定期実行する際の event オブジェクトの中身を調べる

## 概要
- Amazon CloudWatch Events のスケジュール式 (cron または rate 式) で AWS Lambda 関数を定期実行して、渡される情報 (CloudWatch Events Message Event オブジェクト) を確認する

## AWS Lambda 関数に入力するソースコード

ランタイムには Node.js 10.x を使用。

```javascript
exports.handler = async (event, context) => {
    const result = {
        event: event,
        context: context,
        env: process.env,
    };
    // 結果を Amazon CloudWatch Logs に出力する
    console.log(JSON.stringify(result, null, 2));
    return result;
};
```

## 出力結果例

デフォルト設定では AWS Lambda 関数の標準出力は Amazon CloudWatch Logs に出力されるのでそこを確認する。

出力した JSON の event の中身が CloudWatch Events Message Event オブジェクトになっている。

```json
{
    "event": {
        "version": "0",
        "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
        "detail-type": "Scheduled Event",
        "source": "aws.events",
        "account": "XXXXXXXXXXXX",
        "time": "2019-09-03T12:18:00Z",
        "region": "ap-northeast-1",
        "resources": [
            "arn:aws:events:ap-northeast-1:XXXXXXXXXXXX:rule/my-foo-bar-event"
        ],
        "detail": {}
    },
    "context": {
        "callbackWaitsForEmptyEventLoop": true,
        "functionVersion": "$LATEST",
        "functionName": "myNodeJsSystemInfo",
        "memoryLimitInMB": "128",
        "logGroupName": "/aws/lambda/myNodeJsSystemInfo",
        "logStreamName": "2019/09/03/[$LATEST]XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "invokedFunctionArn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:myNodeJsSystemInfo",
        "awsRequestId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    },
    "env": {
        "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST",
        "AWS_SESSION_TOKEN": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "AWS_LAMBDA_LOG_GROUP_NAME": "/aws/lambda/myNodeJsSystemInfo",
        "LAMBDA_TASK_ROOT": "/var/task",
        "LD_LIBRARY_PATH": "/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib",
        "AWS_LAMBDA_RUNTIME_API": "127.0.0.1:9001",
        "AWS_LAMBDA_LOG_STREAM_NAME": "2019/09/03/[$LATEST]XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "AWS_EXECUTION_ENV": "AWS_Lambda_nodejs10.x",
        "AWS_XRAY_DAEMON_ADDRESS": "XXX.XXX.XX.X:2000",
        "AWS_LAMBDA_FUNCTION_NAME": "myNodeJsSystemInfo",
        "PATH": "/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin",
        "AWS_DEFAULT_REGION": "ap-northeast-1",
        "PWD": "/var/task",
        "AWS_SECRET_ACCESS_KEY": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "LAMBDA_RUNTIME_DIR": "/var/runtime",
        "LANG": "en_US.UTF-8",
        "NODE_PATH": "/opt/nodejs/node10/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules",
        "AWS_REGION": "ap-northeast-1",
        "TZ": ":UTC",
        "AWS_ACCESS_KEY_ID": "XXXXXXXXXXXXXXXXXXXX",
        "SHLVL": "0",
        "_AWS_XRAY_DAEMON_ADDRESS": "XXX.XXX.XX.X",
        "_AWS_XRAY_DAEMON_PORT": "2000",
        "AWS_XRAY_CONTEXT_MISSING": "LOG_ERROR",
        "_HANDLER": "index.handler",
        "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "128",
        "_X_AMZN_TRACE_ID": "Root=1-XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX;Parent=XXXXXXXXXXXXXXXX;Sampled=0"
    }
}
```

## 参考資料
- [AWS Lambda を Amazon CloudWatch Events に使用する \- AWS Lambda](https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/with-scheduled-events.html)
- [CloudWatch イベント のイベントパターン \- Amazon CloudWatch Events](https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html)
- [Node\.js の AWS Lambda 関数ハンドラー \- AWS Lambda](https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/nodejs-prog-model-handler.html)