Exemplo n.º 1
0
def process_events(event: Dict, targets: List[Dict]):
    for target in targets:
        arn = target["Arn"]
        changed_event = filter_event_with_target_input_path(target, event)
        try:
            send_event_to_target(arn, changed_event, aws_stack.get_events_target_attributes(target))
        except Exception as e:
            LOG.info(f"Unable to send event notification {truncate(event)} to target {target}: {e}")
Exemplo n.º 2
0
 def _send_to_failure_destination(
     self,
     shard_id,
     start_sequence_num,
     end_sequence_num,
     source_arn,
     func_arn,
     invoke_count,
     status_code,
     batch_size,
     first_record_arrival_time,
     last_record_arrival_time,
     destination,
 ):
     """
     Creates a metadata payload relating to a failed Lambda invocation and delivers it to the given destination
     """
     payload = {
         "version": "1.0",
         "timestamp": timestamp_millis(),
         "requestContext": {
             "requestId": long_uid(),
             "functionArn": func_arn,
             "condition": "RetryAttemptsExhausted",
             "approximateInvokeCount": invoke_count,
         },
         "responseContext": {
             "statusCode": status_code,
             "executedVersion": "$LATEST",  # TODO: don't hardcode these fields
             "functionError": "Unhandled",
         },
     }
     details = {
         "shardId": shard_id,
         "startSequenceNumber": start_sequence_num,
         "endSequenceNumber": end_sequence_num,
         "approximateArrivalOfFirstRecord": first_record_arrival_time,
         "approximateArrivalOfLastRecord": last_record_arrival_time,
         "batchSize": batch_size,
         "streamArn": source_arn,
     }
     payload[self._FAILURE_PAYLOAD_DETAILS_FIELD_NAME] = details
     send_event_to_target(destination, payload)
Exemplo n.º 3
0
 def func(*args, **kwargs):
     rule_name = data.get("Name")
     client = aws_stack.connect_to_service("events")
     targets = client.list_targets_by_rule(Rule=rule_name)["Targets"]
     if targets:
         LOG.debug(
             "Notifying %s targets in response to triggered Events rule %s"
             % (len(targets), rule_name)
         )
     for target in targets:
         arn = target.get("Arn")
         event_str = target.get("Input") or "{}"
         event = json.loads(event_str)
         attr = aws_stack.get_events_target_attributes(target)
         try:
             send_event_to_target(arn, event, target_attributes=attr)
         except Exception as e:
             LOG.info(
                 f"Unable to send event notification {truncate(event)} to target {target}: {e}"
             )