How To

AWS EventBridge infrastructure configuration event

Note: AWS only

If you want to add resources in AWS that are not supported by Coherence but would like to have those resources integrate with Coherence Environments, you can use the EventBridge Event Bus that we send events to.

By default, Coherence creates an EventBridge Event Bus in your non production AWS Account to receive events. Every time that we configure your infrastructure in your non-production account we will send two events to the {your-app-name-and-hash}-coherence-events event stream: one event with a list of all of the current active environments and one event with a list of the new environments that were created on that run of Terraform. This allows you to set up listeners to the event stream, and create any resources on a per environment basis that you like. Those resources can be used within Coherence Environments just like any other AWS resource, but you will need to populate the connection information yourself.

Example new environments event:

{
    "version": "0",
    "id": "1bb332f8-acc2-adcb-0878-4c0fe06aaf7d",
    "detail-type": "new_environments",
    "source": "Coherence",
    "account": "1234596789",
    "time": "2023-05-19T13:56:16Z",
    "region": "us-east-1",
    "resources": [],
    "detail": {
        "new_environments": [
            {
                "cloudfront_id": "AESOIFH3341",
                "environment_name": "another-test-env",
                "application_name": "12309ijsdf-your-app-name"
            }
        ]
    }
}

Example valid environments event:

{
    "version": "0",
    "id": "8573c1ce-132d-af52-c64f-045f162e6107",
    "detail-type": "valid_environments",
    "source": "Coherence",
    "account": "1234596789",
    "time": "2023-05-19T14:15:27Z",
    "region": "us-east-1",
    "resources": [],
    "detail": {
        "valid_environments": [
            {
                "cloudfront_id": "E1LPXKCLUIFVWG",
                "environment_name": "main",
                "application_name": "12309ijsdf-your-app-name"
            },
            {
                "cloudfront_id": "E1JAHDXHMQLLSJ",
                "environment_name": "update-subscribe-button",
                "application_name": "12309ijsdf-your-app-name"
            },
            {
                "cloudfront_id": "E2QXXI0WZW0C68",
                "environment_name": "another-test-env",
                "application_name": "12309ijsdf-your-app-name"
            },
            {
                "cloudfront_id": "E39Y1123213",
                "environment_name": "some-env-name",
                "application_name": "12309ijsdf-your-app-name"
            }
        ]
    }
}

You can set up a Rule in Amazon EventBridge to forward these events to another AWS service (like a Lambda function) to take further actions in your AWS Account based on the event. Create a new Rule in EventBridge and select the coherence-events Event Bus as the the event bus for your rule. Then select Rule with Event Pattern here: AWS Rule with Event Pattern Screenshot

Click Next to go to the next screen to build your event pattern and select Other as the Event Source for your rule. If you wanted to filter only new_environment events, your pattern would look like this: AWS Event Pattern Builder Screenshot

On the next screen you can select your target for the rule. This is where the events will be forwarded to from the rule. To a forward to an AWS Lambda called log-events your configuration will look like this: AWS Event Target Screenshot

Finish creating your rule, and your Coherence event stream should be sent to your lambda where you can do whatever processing you need.

Previous
Run integration tests