HomeCloud ComputingMonitor and debug event-driven functions with new Amazon EventBridge logging

Monitor and debug event-driven functions with new Amazon EventBridge logging


Voiced by Polly

Beginning right this moment, you should use enhanced logging functionality in Amazon EventBridge to watch and debug your event-driven functions with complete logs. These new enhancements assist enhance the way you monitor and troubleshoot occasion flows.

Right here’s how you will discover this new functionality on the Amazon EventBridge console:

The brand new observability capabilities tackle microservices and event-driven structure monitoring challenges by offering complete occasion lifecycle monitoring. EventBridge now generates detailed log entries each time a matched occasion towards guidelines is revealed, delivered to subscribers, or encounters failures and retries.

You acquire visibility into the whole occasion journey with detailed details about successes, failures, and standing codes that make figuring out and diagnosing points easy. What used to take hours of trial-and-error debugging now takes minutes with detailed occasion lifecycle monitoring and built-in question instruments.

Utilizing Amazon EventBridge enhanced observability
Let me stroll you thru an illustration that showcases the logging functionality in Amazon EventBridge.

I can allow logging for an current occasion bus or when creating a brand new customized occasion bus. First, I navigate to the EventBridge console and select Occasion buses within the left navigation pane. In Customized occasion bus, I select Create occasion bus.

I can see this new functionality within the Logs part. I’ve three choices to configure the Log vacation spot: Amazon CloudWatch Logs, Amazon Knowledge Firehose Stream, and Amazon Easy Storage Service (Amazon S3). If I wish to stream my logs into a knowledge lake, I can choose Amazon Kinesis Knowledge Firehose Stream. Logs are encrypted in transit with TLS and at relaxation if a customer-managed key (CMK) is supplied for the occasion bus. CloudWatch Logs helps customer-managed keys, and Knowledge Firehose provides server-side encryption for downstream locations.

For this demo, I choose CloudWatch logs and S3 logs.

I can even select Log degree, from Error, Data, or Hint. I select Hint and choose Embrace execution knowledge as a result of I must evaluation the payloads. You want to be aware as logging payload knowledge might include delicate info, and this setting applies to all log locations you choose. Then, I configure two locations, one every for CloudWatch log group and S3 logs. Then I select Create.

After logging is enabled, I can begin publishing check occasions to look at the logging habits.

For the primary state of affairs, I’ve constructed an AWS Lambda operate and configured this Lambda operate as a goal.

I navigate to my occasion bus to ship a pattern occasion by selecting Ship occasions.

Right here’s the payload that I take advantage of:

{
  "Supply": "ecommerce.orders",
  "DetailType": "Order Positioned",
  "Element": {
    "orderId": "12345",
    "customerId": "cust-789",
    "quantity": 99.99,
    "gadgets": [
      {
        "productId": "prod-456",
        "quantity": 2,
        "price": 49.99
      }
    ]
  }
}

After I despatched the pattern occasion, I can see the logs can be found in my S3 bucket.

I can even see the log entries showing within the Amazon CloudWatch logs. The logs present the occasion lifecycle, from EVENT_RECEIPT to SUCCESS. Study extra in regards to the full occasion lifecycle on What Amazon EventBridge logs for occasion buses documentation web page.

Now, let’s consider these logs. For brevity, I solely embrace a couple of logs and have redacted them for readability. Right here’s the log from after I triggered the occasion:

{
    "resource_arn": "arn:aws:occasions:us-east-1:123:event-bus/demo-logging",
    "message_timestamp_ms": 1751608776896,
    "event_bus_name": "demo-logging",
// REDACTED FOR BREVITY //
    "message_type": "EVENT_RECEIPT",
    "log_level": "TRACE",
    "particulars": {
        "caller_account_id": "123",
        "source_time_ms": 1751608775000,
        "supply": "ecommerce.orders",
        "detail_type": "Order Positioned",
        "assets": [],
        "event_detail": "REDACTED FOR BREVITY"
    }
}

Right here’s the log when the occasion was efficiently invoked:

{
    "resource_arn": "arn:aws:occasions:us-east-1:123:event-bus/demo-logging",
    "message_timestamp_ms": 1751608777091,
    "event_bus_name": "demo-logging",
// REDACTED FOR BREVITY //
    "message_type": "INVOCATION_SUCCESS",
    "log_level": "INFO",
    "particulars": {
// REDACTED FOR BREVITY //
        "total_attempts": 1,
        "final_invocation_status": "SUCCESS",
        "ingestion_to_start_latency_ms": 105,
        "ingestion_to_complete_latency_ms": 183,
        "ingestion_to_success_latency_ms": 183,
        "target_duration_ms": 53,
        "target_response_body": "",
        "http_status_code": 202
    }
}

The extra log entries embrace wealthy metadata that makes troubleshooting easy. For instance, on a profitable occasion, I can see the latency timing from beginning to finishing the occasion, length for the goal to complete processing, and HTTP standing code.

Debugging failures with full occasion lifecycle monitoring
The good thing about EventBridge logging turns into obvious when issues go incorrect. To check failure situations, I deliberately misconfigure a Lambda operate’s permissions and alter the rule to level to a special Lambda operate with out correct permissions.

The try failed with a everlasting failure resulting from lacking permissions. The log exhibits it’s a FIRST try that resulted in NO_PERMISSIONS standing.

{
    "message_type": "INVOCATION_ATTEMPT_PERMANENT_FAILURE",
    "log_level": "ERROR",
    "particulars": {
        "rule_arn": "arn:aws:occasions:us-east-1:123:rule/demo-logging/demo-order-placed",
        "role_arn": "arn:aws:iam::123:function/service-role/Amazon_EventBridge_Invoke_Lambda_123",
        "target_arn": "arn:aws:lambda:us-east-1:123:operate:demo-evb-fail",
        "attempt_type": "FIRST",
        "attempt_count": 1,
        "invocation_status": "NO_PERMISSIONS",
        "target_duration_ms": 25,
        "target_response_body": "{"requestId":"a4bdfdc9-4806-4f3e-9961-31559cb2db62","errorCode":"AccessDeniedException","errorType":"Consumer","errorMessage":"Consumer: arn:aws:sts::123:assumed-role/Amazon_EventBridge_Invoke_Lambda_123/db4bff0a7e8539c4b12579ae111a3b0b shouldn't be approved to carry out: lambda:InvokeFunction on useful resource: arn:aws:lambda:us-east-1:123:operate:demo-evb-fail as a result of no identity-based coverage permits the lambda:InvokeFunction motion","statusCode":403}",
        "http_status_code": 403
    }
}

The ultimate log entry summarizes the whole failure with timing metrics and the precise error message.

{
    "message_type": "INVOCATION_FAILURE",
    "log_level": "ERROR",
    "particulars": {
        "rule_arn": "arn:aws:occasions:us-east-1:123:rule/demo-logging/demo-order-placed",
        "role_arn": "arn:aws:iam::123:function/service-role/Amazon_EventBridge_Invoke_Lambda_123",
        "target_arn": "arn:aws:lambda:us-east-1:123:operate:demo-evb-fail",
        "total_attempts": 1,
        "final_invocation_status": "NO_PERMISSIONS",
        "ingestion_to_start_latency_ms": 62,
        "ingestion_to_complete_latency_ms": 114,
        "target_duration_ms": 25,
        "http_status_code": 403
    },
    "error": {
        "http_status_code": 403,
        "error_message": "Consumer: arn:aws:sts::123:assumed-role/Amazon_EventBridge_Invoke_Lambda_123/db4bff0a7e8539c4b12579ae111a3b0b shouldn't be approved to carry out: lambda:InvokeFunction on useful resource: arn:aws:lambda:us-east-1:123:operate:demo-evb-fail as a result of no identity-based coverage permits the lambda:InvokeFunction motion",
        "aws_service": "AWSLambda",
        "request_id": "a4bdfdc9-4806-4f3e-9961-31559cb2db62"
    }
}

The logs present detailed efficiency metrics that assist determine bottlenecks. The ingestion_to_start_latency_ms: 62 exhibits the time from occasion ingestion to beginning invocation, whereas ingestion_to_complete_latency_ms: 114 represents the whole time from ingestion to completion. Moreover, target_duration_ms: 25 signifies how lengthy the goal service took to reply, serving to distinguish between EventBridge processing time and goal service efficiency.

The error message clearly states what failed, lambda:InvokeFunction motion, why it failed, (no identity-based coverage permits the motion), which function was concerned (Amazon_EventBridge_Invoke_Lambda_1428392416), and which particular useful resource was affected, which was indicated by the Lambda operate Amazon Useful resource Identify (ARN).

Debugging API Locations with EventBridge Logging
One specific use case that I believe EventBridge logging functionality might be useful is to debug points with API locations. EventBridge API locations are HTTPS endpoints that you may invoke because the goal of an occasion bus rule or pipe. HTTPS endpoints assist you to to route occasions out of your occasion bus to exterior programs, software-as-a-service (SaaS) functions, or third-party APIs utilizing HTTPS calls. They use connections to deal with authentication and credentials, making it simple to combine your event-driven structure with any HTTPS-based service. 

API locations are generally used to ship occasions to exterior HTTPS endpoints and debugging failures from the exterior endpoint could be a problem. These issues usually stem from adjustments to the endpoint authentication necessities or modified credentials.

To exhibit this debugging functionality, I deliberately configured an API vacation spot with incorrect credentials within the connection useful resource.

Once I ship an occasion to this misconfigured endpoint, the improved logging exhibits the foundation reason for this failure.

{
    "resource_arn": "arn:aws:occasions:us-east-1:123:event-bus/demo-logging",
    "message_timestamp_ms": 1750344097251,
    "event_bus_name": "demo-logging",
    //REDACTED FOR BREVITY//,
    "message_type": "INVOCATION_FAILURE",
    "log_level": "ERROR",
    "particulars": {
        //REDACTED FOR BREVITY//,
        "total_attempts": 1,
        "final_invocation_status": "SDK_CLIENT_ERROR",
        "ingestion_to_start_latency_ms": 135,
        "ingestion_to_complete_latency_ms": 549,
        "target_duration_ms": 327,
        "target_response_body": "",
        "http_status_code": 400
    },
    "error": {
        "http_status_code": 400,
        "error_message": "Unable to invoke ApiDestination endpoint: The request failed as a result of the credentials included for the connection should not approved for the API vacation spot."
    }
}

The log supplies speedy readability in regards to the failure. The target_arn exhibits this includes an API vacation spot, the final_invocation_status signifies SDK_CLIENT_ERROR, and the http_status_code of 400 , which factors to a client-side situation. Most significantly, the error_message explicitly states that: Unable to invoke ApiDestination endpoint: The request failed as a result of the credentials included for the connection should not approved for the API vacation spot.

This entire log sequence supplies helpful debugging insights as a result of I can see precisely how the occasion moved via EventBridge — from occasion receipt, to ingestion, to rule matching, to invocation makes an attempt. This degree of element eliminates guesswork and factors on to the foundation reason for the problem.

Further issues to know
Listed below are a few issues to notice:

  • Structure assist – Logging works with all EventBridge options together with customized occasion buses, associate occasion sources, and API locations for HTTPS endpoints.
  • Efficiency affect – Logging operates asynchronously with no measurable affect on occasion processing latency or throughput.
  • Pricing – You pay commonplace Amazon S3, Amazon CloudWatch Logs or Amazon Knowledge Firehose pricing for log storage and supply. EventBridge logging itself incurs no further costs. For particulars, go to the Amazon EventBridge pricing web page .
  • Availability – Amazon EventBridge logging functionality is accessible in all AWS Areas the place EventBridge is supported.
  • Documentation — For extra particulars, seek advice from the Amazon EventBridge monitoring and debugging Documentation.

Get began with Amazon EventBridge logging functionality by visiting the EventBridge console and enabling logging in your occasion buses.

Pleased constructing!
— Donnie 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments