Skip to content

Instantly share code, notes, and snippets.

@noid11
Last active December 13, 2020 13:07
Show Gist options
  • Save noid11/4aa8933d0b5cdbcc09d377c5d65d28c1 to your computer and use it in GitHub Desktop.
Save noid11/4aa8933d0b5cdbcc09d377c5d65d28c1 to your computer and use it in GitHub Desktop.
API Gateway WebSocket API で Lambda 関数が受け取る event サンプル

$connect

{
    "headers": {
        "Host": "xxx.execute-api.ap-northeast-1.amazonaws.com",
        "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",
        "Sec-WebSocket-Key": "X/MA+DSRXZ8WnITjBpxm3g==",
        "Sec-WebSocket-Version": "13",
        "X-Amzn-Trace-Id": "Root=1-5fd5ea4b-35d888b22f86c62d26beae28",
        "X-Forwarded-For": "203.0.113.0",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },
    "multiValueHeaders": {
        "Host": [
            "xxx.execute-api.ap-northeast-1.amazonaws.com"
        ],
        "Sec-WebSocket-Extensions": [
            "permessage-deflate; client_max_window_bits"
        ],
        "Sec-WebSocket-Key": [
            "X/MA+DSRXZ8WnITjBpxm3g=="
        ],
        "Sec-WebSocket-Version": [
            "13"
        ],
        "X-Amzn-Trace-Id": [
            "Root=1-5fd5ea4b-35d888b22f86c62d26beae28"
        ],
        "X-Forwarded-For": [
            "203.0.113.0"
        ],
        "X-Forwarded-Port": [
            "443"
        ],
        "X-Forwarded-Proto": [
            "https"
        ]
    },
    "requestContext": {
        "routeKey": "$connect",
        "disconnectStatusCode": null,
        "messageId": null,
        "eventType": "CONNECT",
        "extendedRequestId": "XfGLwFTktjMFsLg=",
        "requestTime": "13/Dec/2020:10:17:47 +0000",
        "messageDirection": "IN",
        "disconnectReason": null,
        "stage": "dev",
        "connectedAt": 1607854667185,
        "requestTimeEpoch": 1607854667186,
        "identity": {
            "cognitoIdentityPoolId": null,
            "cognitoIdentityId": null,
            "principalOrgId": null,
            "cognitoAuthenticationType": null,
            "userArn": null,
            "userAgent": null,
            "accountId": null,
            "caller": null,
            "sourceIp": "203.0.113.0",
            "accessKey": null,
            "cognitoAuthenticationProvider": null,
            "user": null
        },
        "requestId": "XfGLwFTktjMFsLg=",
        "domainName": "xxx.execute-api.ap-northeast-1.amazonaws.com",
        "connectionId": "XfGLwcD_tjMCItg=",
        "apiId": "xxx"
    },
    "isBase64Encoded": false
}

$disconnect

{
    "headers": {
        "Host": "xxx.execute-api.ap-northeast-1.amazonaws.com",
        "x-api-key": "",
        "X-Forwarded-For": "",
        "x-restapi": ""
    },
    "multiValueHeaders": {
        "Host": [
            "xxx.execute-api.ap-northeast-1.amazonaws.com"
        ],
        "x-api-key": [
            ""
        ],
        "X-Forwarded-For": [
            ""
        ],
        "x-restapi": [
            ""
        ]
    },
    "requestContext": {
        "routeKey": "$disconnect",
        "disconnectStatusCode": 1000,
        "messageId": null,
        "eventType": "DISCONNECT",
        "extendedRequestId": "Xfbq5EEWNjMFk5A=",
        "requestTime": "13/Dec/2020:12:44:28 +0000",
        "messageDirection": "IN",
        "disconnectReason": "Connection Closed Normally",
        "stage": "dev",
        "connectedAt": 1607862933062,
        "requestTimeEpoch": 1607863468077,
        "identity": {
            "cognitoIdentityPoolId": null,
            "cognitoIdentityId": null,
            "principalOrgId": null,
            "cognitoAuthenticationType": null,
            "userArn": null,
            "userAgent": null,
            "accountId": null,
            "caller": null,
            "sourceIp": "203.0.113.0",
            "accessKey": null,
            "cognitoAuthenticationProvider": null,
            "user": null
        },
        "requestId": "Xfbq5EEWNjMFk5A=",
        "domainName": "xxx.execute-api.ap-northeast-1.amazonaws.com",
        "connectionId": "XfaXTd_ptjMCI7w=",
        "apiId": "xxx"
    },
    "isBase64Encoded": false
}

$default

{
    "requestContext": {
        "routeKey": "$default",
        "disconnectStatusCode": null,
        "messageId": "XfayEeafNjMCI7w=",
        "eventType": "MESSAGE",
        "extendedRequestId": "XfayEFzxtjMFmow=",
        "requestTime": "13/Dec/2020:12:38:24 +0000",
        "messageDirection": "IN",
        "disconnectReason": null,
        "stage": "dev",
        "connectedAt": 1607862933062,
        "requestTimeEpoch": 1607863104389,
        "identity": {
            "cognitoIdentityPoolId": null,
            "cognitoIdentityId": null,
            "principalOrgId": null,
            "cognitoAuthenticationType": null,
            "userArn": null,
            "userAgent": null,
            "accountId": null,
            "caller": null,
            "sourceIp": "203.0.113.0",
            "accessKey": null,
            "cognitoAuthenticationProvider": null,
            "user": null
        },
        "requestId": "XfayEFzxtjMFmow=",
        "domainName": "xxx.execute-api.ap-northeast-1.amazonaws.com",
        "connectionId": "XfaXTd_ptjMCI7w=",
        "apiId": "xxx"
    },
    "isBase64Encoded": false
}

body あり

{
    "requestContext": {
        "routeKey": "$default",
        "disconnectStatusCode": null,
        "messageId": "XfdO_dz4NjMCJJQ=",
        "eventType": "MESSAGE",
        "extendedRequestId": "XfdO_G2_tjMFm-A=",
        "requestTime": "13/Dec/2020:12:55:08 +0000",
        "messageDirection": "IN",
        "disconnectReason": null,
        "stage": "dev",
        "connectedAt": 1607864094597,
        "requestTimeEpoch": 1607864108633,
        "identity": {
            "cognitoIdentityPoolId": null,
            "cognitoIdentityId": null,
            "principalOrgId": null,
            "cognitoAuthenticationType": null,
            "userArn": null,
            "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0",
            "accountId": null,
            "caller": null,
            "sourceIp": "203.0.113.0",
            "accessKey": null,
            "cognitoAuthenticationProvider": null,
            "user": null
        },
        "requestId": "XfdO_G2_tjMFm-A=",
        "domainName": "xxx.execute-api.ap-northeast-1.amazonaws.com",
        "connectionId": "XfdMydxYtjMCJJQ=",
        "apiId": "xxx"
    },
    "body": "Rock it with HTML5 WebSocket",
    "isBase64Encoded": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment