

# Integrating event-driven applications with Service Quotas using Amazon EventBridge
Integrating Service Quotas into EDAs

With Amazon EventBridge rules, you can monitor Service Quotas events and AWS Health notifications to automate responses when quotas change or approach their limits. To monitor these Service Quotas events, you'll need to [start Service Quotas Automatic Management](getting-started-auto-mgmt.md). These events trigger remediation actions when quota utilization changes occur.

You do this by using Amazon EventBridge to route events from Service Quotas to other software components. Amazon EventBridge is a serverless service that uses events to connect application components together, making it easier for you to integrate AWS services like Service Quotas into event-driven architectures without additional code and operations.

**Topics**
+ [

## How EventBridge routes Service Quotas events
](#eventbridge-routes-service-events)
+ [

## Service Quotas events
](#eventbridge-service-events)
+ [

## Creating event patterns that match Service Quotas events
](#eventbridge-event-delivery-filter)
+ [

## Receiving events from EventBridge
](#eventbridge-service-as-target)

## How EventBridge routes Service Quotas events


Here's how EventBridge works with Service Quotas events:

As with many AWS services, Service Quotas generates and sends events to the EventBridge default *event bus*. An event bus is a router that receives events and routes them to the destinations, or *targets*, that you specify. Targets can include other AWS services, custom applications, and SaaS partner applications. 

EventBridge routes events according to *rules* you create on the event bus. For each rule, you specify a filter, or *event pattern*, to select only the events you want. Whenever an event is sent to the event bus, EventBridge compares it against each rule. If the event matches the rule, EventBridge routes the event to the specified target(s).

![\[AWS services send events to the EventBridge default event bus. If the event matches a rule's event pattern, EventBridge routes the event to the targets specified for that rule.\]](http://docs.aws.amazon.com/servicequotas/latest/userguide/images/eventbridge-integration-how-it-works.png)


## Service Quotas events


For a list of Service Quotas events sent to EventBridge, refer to the Service Quotas topic in the [https://docs.aws.amazon.com/eventbridge/latest/ref/welcome.html](https://docs.aws.amazon.com/eventbridge/latest/ref/welcome.html).

### Event structure
Event structure

All events from AWS services contain two types of data:
+ A common set of fields containing metadata about the event, such as the AWS service that is the source of the event, the time the event was generated, the account and region in which the event took place, and others. For definitions of these general fields, see [Event structure ](https://docs.aws.amazon.com/eventbridge/latest/ref/overiew-event-structure.html) in the *Amazon EventBridge Events Reference*. 
+ A `detail` field that contains data specific to that particular service event. 

### Service Quotas event delivery via AWS CloudTrail
Events via AWS CloudTrail

AWS services can send events directly to the EventBridge default event bus. In addition, AWS CloudTrail sends events originating from numerous AWS services to EventBridge as well. These events can include API calls, console signins and actions, service events, and CloudTrail Insights. For more information, see [AWS service events delivered via AWS CloudTrail](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event-cloudtrail.html) in the *EventBridge User Guide*. 

## Creating event patterns that match Service Quotas events
Creating event patterns

Event patterns are filters that specify the data to match the events you want to select.

Each event pattern is a JSON object that contains:
+ A `source` attribute that identifies the service sending the event. For Service Quotas events generated by Automatic Management, the source is `aws.health`.
+ A `detail-type` attribute set to `AWS Health Events`, which specifies the type of event.
+ A `detail` attribute containing the following fields:
  + A `service` field set to `SERVICEQUOTAS`
  + An `eventTypeCode` field that matches one or more of these values:
    + `AWS_SERVICEQUOTAS_APPROACHING_THRESHOLD`
    + `AWS_SERVICEQUOTAS_INCREASE_REQUEST_FAILED`
    + `AWS_SERVICEQUOTAS_THRESHOLD_BREACH`
  + An `eventTypeCategory` field set to `accountNotification`

For example, the following event pattern would select all *Event Name* events from Service Quotas:

```
{
    "source": ["aws.health"],
    "detail-type": ["AWS Health Event"],
    "detail": {
        "service": ["SERVICEQUOTAS"],
        "eventTypeCode": [
            "AWS_SERVICEQUOTAS_THRESHOLD_BREACH",
            "AWS_SERVICEQUOTAS_INCREASE_REQUEST_FAILED",
            "AWS_SERVICEQUOTAS_APPROACHING_THRESHOLD"
        ],
        "eventTypeCategory": ["accountNotification"]
    }
}
```

The following describes the different event type codes.
+ `AWS_SERVICEQUOTAS_THRESHOLD_BREACH` - Tracks Service Quotas that cannot be adjusted. You'll need to optimize your quota utilization to mitigate further Service Quota threshold breach.
+ `AWS_SERVICEQUOTAS_INCREASE_REQUEST_FAILED` - Tracks failed attempts to automatically increase service quotas when usage thresholds are exceeded.
+ `AWS_SERVICEQUOTAS_APPROACHING_THRESHOLD` - Tracks Service Quotas that can be adjusted. You can optimize your quota utilization or request a quota increase to mitigate further Service Quota approaching threshold.

For more information on writing event patterns, see [Event patterns](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html) in the *EventBridge User Guide*.

## Receiving events from EventBridge
Receiving events

With Service Quotas Automatic Management, you can specify your custom applications as targets for EventBridge rules. This enables your applications to receive events from AWS services like Service Quotas. For more information, see [Creating rules that react to events](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule.html) in the *EventBridge User Guide*. 

For a full list of the AWS services that you can specify as targets, see [Target types](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-targets.html#eb-console-targets) in the *EventBridge Events Reference*. 