Search in sources :

Example 1 with S3BucketEntity

use of com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity in project bender by Nextdoor.

the class S3HandlerTest method getTestEvent.

@Override
public S3EventNotification getTestEvent() throws Exception {
    /*
     * Upload a test resoruce to the mock S3
     */
    String payload = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
    this.client.putObject(S3_BUCKET, "basic_input.log", payload);
    /*
     * Create a S3EventNotification event
     */
    S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
    S3BucketEntity bucketEntity = new S3BucketEntity(S3_BUCKET, null, null);
    S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
    S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, "1970-01-01T00:00:00.000Z", null, null, null, entity, null);
    List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
    notifications.add(rec);
    return new S3EventNotification(notifications);
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) InputStreamReader(java.io.InputStreamReader) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) S3BucketEntity(com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity)

Example 2 with S3BucketEntity

use of com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity in project bender by Nextdoor.

the class SNSS3HandlerTest method getTestEvent.

@Override
public SNSEvent getTestEvent() throws Exception {
    /*
     * Upload a test resoruce to the mock S3
     */
    String payload = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
    this.client.putObject(S3_BUCKET, "basic_input.log", payload);
    /*
     * Create a S3EventNotification event
     */
    S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
    S3BucketEntity bucketEntity = new S3BucketEntity(S3_BUCKET, null, null);
    S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
    S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, "1970-01-01T00:00:00.000Z", null, null, null, entity, null);
    List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
    notifications.add(rec);
    /*
     * Wrap as an SNS Event
     */
    S3EventNotification event = new S3EventNotification(notifications);
    SNSEvent.SNS sns = new SNSEvent.SNS();
    sns.setMessage(event.toJson());
    SNSEvent snsEvent = new SNSEvent();
    ArrayList<SNSRecord> snsRecords = new ArrayList<SNSRecord>(1);
    SNSRecord snsRecord = new SNSRecord();
    snsRecord.setEventSource("aws:sns");
    snsRecord.setEventVersion("1.0");
    snsRecord.setEventSubscriptionArn("arn");
    snsRecord.setSns(sns);
    snsRecords.add(snsRecord);
    snsEvent.setRecords(snsRecords);
    return snsEvent;
}
Also used : S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) S3BucketEntity(com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity) SNSEvent(com.amazonaws.services.lambda.runtime.events.SNSEvent) S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) SNSRecord(com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord)

Example 3 with S3BucketEntity

use of com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity in project bender by Nextdoor.

the class SNSS3HandlerTest method getTestEvent.

private SNSEvent getTestEvent(String bucket, boolean doPut) throws Exception {
    /*
     * Upload a test resoruce to the mock S3
     */
    if (doPut) {
        String payload = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
        this.client.putObject(bucket, "basic_input.log", payload);
    }
    /*
     * Create a S3EventNotification event
     */
    S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
    S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
    S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
    S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, "1970-01-01T00:00:00.000Z", null, null, null, entity, null);
    List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
    notifications.add(rec);
    /*
     * Wrap as an SNS Event
     */
    S3EventNotification event = new S3EventNotification(notifications);
    SNSEvent.SNS sns = new SNSEvent.SNS();
    sns.setMessage(event.toJson());
    SNSEvent snsEvent = new SNSEvent();
    ArrayList<SNSRecord> snsRecords = new ArrayList<SNSRecord>(1);
    SNSRecord snsRecord = new SNSRecord();
    snsRecord.setEventSource("aws:sns");
    snsRecord.setEventVersion("1.0");
    snsRecord.setEventSubscriptionArn("arn");
    snsRecord.setSns(sns);
    snsRecords.add(snsRecord);
    snsEvent.setRecords(snsRecords);
    return snsEvent;
}
Also used : S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) S3BucketEntity(com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity) SNSEvent(com.amazonaws.services.lambda.runtime.events.SNSEvent) S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) SNSRecord(com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord)

Example 4 with S3BucketEntity

use of com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity in project bender by Nextdoor.

the class S3SnsNotifier method getS3Notification.

public static S3EventNotification getS3Notification(String key, String bucket, long size) {
    S3ObjectEntity objEntity = new S3ObjectEntity(key, size, null, null);
    S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
    S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
    String timestamp = formatter.print(System.currentTimeMillis());
    S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, timestamp, null, null, null, entity, null);
    List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(1);
    notifications.add(rec);
    return new S3EventNotification(notifications);
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) S3BucketEntity(com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity)

Example 5 with S3BucketEntity

use of com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity in project bender by Nextdoor.

the class S3HandlerTest method getTestEvent.

private S3EventNotification getTestEvent(String bucket, boolean doPut) throws Exception {
    /*
     * Upload a test resoruce to the mock S3
     */
    if (doPut) {
        String payload = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
        this.client.putObject(bucket, "basic_input.log", payload);
    }
    /*
     * Create a S3EventNotification event
     */
    S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
    S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
    S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
    S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, "1970-01-01T00:00:00.000Z", null, null, null, entity, null);
    List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
    notifications.add(rec);
    return new S3EventNotification(notifications);
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) InputStreamReader(java.io.InputStreamReader) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) S3BucketEntity(com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity)

Aggregations

S3EventNotification (com.amazonaws.services.s3.event.S3EventNotification)5 S3BucketEntity (com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity)5 S3Entity (com.amazonaws.services.s3.event.S3EventNotification.S3Entity)5 S3EventNotificationRecord (com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord)5 S3ObjectEntity (com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity)5 ArrayList (java.util.ArrayList)5 InputStreamReader (java.io.InputStreamReader)4 SNSEvent (com.amazonaws.services.lambda.runtime.events.SNSEvent)2 SNSRecord (com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord)2