Skip to content

Adding EventBridgeEvent #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.services.lambda.runtime.events;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;
import java.util.List;

/**
* Object representation of an Amazon EventBridge event.
*
* @see <a href="https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html">Using AWS Lambda with Amazon EventBridge (CloudWatch Events)</a>
*
* @author msailes <[email protected]>
*/
@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public class EventBridgeEvent<T> {

private String version;

private String id;

@JsonProperty("detail-type")
private String detailType;

private String source;

private String account;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssX", timezone = "UTC")
private Instant time;

private String region;

private List<String> resources;

private T detail;
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ public void testDynamodbTimeWindowEvent() throws IOException {
assertJsonEqual(expected, actual);
}

@Test
public void testEventBridgeEvent() throws IOException {
String expected = EventUtils.readEvent("eventbridge_event.json");
String actual = deserializeSerializeJsonToString(expected, EventBridgeEvent.class);

assertJsonEqual(expected, actual);
}

@Test
public void testIamPolicyResponse() throws IOException {
String expected = EventUtils.readEvent("iam_policy_response.json");
Expand Down Expand Up @@ -516,7 +524,7 @@ public void testTimeWindowEventResponse() throws IOException {
assertJsonEqual(expected, actual);
}

private <T> String deserializeSerializeJsonToString(String expected, Class<T> modelClass) throws IOException {
private <T> String deserializeSerializeJsonToString(String expected, Class<T> modelClass) {
T event = CUSTOM_POJO_SERIALIZER.fromJson(expected, modelClass);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0",
"id": "fe8d3c65-xmpl-c5c3-2c87-81584709a377",
"detail-type": "RDS DB Instance Event",
"source": "aws.rds",
"account": "123456789012",
"time": "2020-04-28T07:20:20Z",
"region": "us-east-2",
"resources": [
"arn:aws:rds:us-east-2:123456789012:db:rdz6xmpliljlb1"
],
"detail": {
"EventCategories": [
"backup"
],
"SourceType": "DB_INSTANCE",
"SourceArn": "arn:aws:rds:us-east-2:123456789012:db:rdz6xmpliljlb1",
"Date": "2020-04-28T07:20:20.112Z",
"Message": "Finished DB Instance backup",
"SourceIdentifier": "rdz6xmpliljlb1"
}
}