コード例 #1
0
def _parse_appsync(event: dict) -> dict:
    headers = safe_get(event, ["context", "request", "headers"])
    if not headers:
        headers = safe_get(event, ["request", "headers"])
    host = headers.get("host")
    trace_id = headers.get("x-amzn-trace-id")
    message_id = safe_split_get(trace_id, "=", -1)
    return {"triggeredBy": "appsync", "api": host, "messageId": message_id}
コード例 #2
0
 def __init__(self, event):
     """
     Cache propeties of the event in order improve performance.
     """
     self.raw_event = event
     self.record_event_source = safe_get(event,
                                         ["Records", 0, "eventSource"])
コード例 #3
0
def _parse_streams(event: dict) -> Dict[str, str]:
    """
    :return: {"triggeredBy": str, "arn": str}
    If has messageId, return also: {"messageId": str}
    """
    triggered_by = event["Records"][0]["eventSource"].split(":")[1]
    result = {"triggeredBy": triggered_by, RECORDS_NUM: len(event["Records"])}
    if triggered_by == "s3":
        result["arn"] = event["Records"][0]["s3"]["bucket"]["arn"]
        result["messageId"] = (
            event["Records"][0].get("responseElements", {}).get("x-amz-request-id")
        )
    else:
        result["arn"] = event["Records"][0]["eventSourceARN"]
    if triggered_by == "sqs":
        result.update(_parse_sqs_event(event))
    elif triggered_by == "kinesis":
        result[MESSAGE_ID_KEY] = safe_get(event, ["Records", 0, "kinesis", "sequenceNumber"])
        event_id = safe_get(event, ["Records", 0, "eventID"])
        if isinstance(event_id, str):
            result["shardId"] = event_id.split(":", 1)[0]
    elif triggered_by == "dynamodb":
        result.update(_parse_dynamomdb_event(event))
    return result
コード例 #4
0
 def is_supported(event: Event) -> bool:
     return safe_get(event.raw_event,
                     ["Records", 0, "EventSource"]) == "aws:sns"
コード例 #5
0
 def is_supported(event: Event) -> bool:
     return bool(
         safe_get(event.raw_event,
                  ["Records", 0, "cf", "config", "distributionId"], {}))
コード例 #6
0
 def _extract_message_id(response_body: bytes) -> Optional[str]:
     return safe_key_from_json(
         response_body, "SequenceNumber") or safe_get(  # type: ignore
             safe_key_from_json(response_body, "Records", []),
             [0, "SequenceNumber"]  # type: ignore
         )
コード例 #7
0
def test_safe_get(d, keys, result_value, default):
    assert safe_get(d, keys, default) == result_value
コード例 #8
0
def _is_appsync(event: dict) -> bool:
    host = safe_get(event, ["context", "request", "headers", "host"])
    if not host:
        host = safe_get(event, ["request", "headers", "host"])
    return isinstance(host, str) and "appsync-api" in host