Example usage for com.amazonaws.services.s3.model BucketNotificationConfiguration BucketNotificationConfiguration

List of usage examples for com.amazonaws.services.s3.model BucketNotificationConfiguration BucketNotificationConfiguration

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model BucketNotificationConfiguration BucketNotificationConfiguration.

Prototype

public BucketNotificationConfiguration() 

Source Link

Document

Creates a new bucket notification configuration.

Usage

From source file:com.eucalyptus.cloudformation.resources.standard.actions.AWSS3BucketResourceAction.java

License:Open Source License

private BucketNotificationConfiguration convertNotificationConfiguration(
        S3NotificationConfiguration notificationConfiguration) {
    BucketNotificationConfiguration bucketNotificationConfiguration = new BucketNotificationConfiguration();
    if (notificationConfiguration.getTopicConfigurations() != null) {
        Collection<BucketNotificationConfiguration.TopicConfiguration> topicConfigurations = Lists
                .newArrayList();// w  ww .  j a v  a 2  s. co  m
        for (S3NotificationTopicConfiguration s3NotificationTopicConfiguration : notificationConfiguration
                .getTopicConfigurations()) {
            topicConfigurations.add(new BucketNotificationConfiguration.TopicConfiguration(
                    s3NotificationTopicConfiguration.getTopic(), s3NotificationTopicConfiguration.getEvent()));
        }
        bucketNotificationConfiguration.setTopicConfigurations(topicConfigurations);
    }
    return bucketNotificationConfiguration;
}

From source file:com.tvarit.plugin.S3WarUploadEventToInvokeLambdaMaker.java

License:Open Source License

void make(AmazonS3Client amazonS3Client, String bucketName, Stack stack) {
    final List<Output> outputs = stack.getOutputs();
    final String lambdaFunctionArn = outputs.stream()
            .filter(output -> output.getOutputKey().equals("LambdaFunctionArn")).findFirst().get()
            .getOutputValue();//w  w w . j a  v  a  2 s . c  o  m
    final BucketNotificationConfiguration notificationConfiguration = new BucketNotificationConfiguration();
    final HashMap<String, NotificationConfiguration> configurations = new HashMap<>();
    final LambdaConfiguration lambdaConfiguration = new LambdaConfiguration(lambdaFunctionArn);
    final HashSet<String> events = new HashSet<>();
    events.add("s3:ObjectCreated:*");
    lambdaConfiguration.setEvents(events);
    final com.amazonaws.services.s3.model.Filter notificationFilter = new com.amazonaws.services.s3.model.Filter();
    final S3KeyFilter s3KeyFilter = new S3KeyFilter();
    notificationFilter.withS3KeyFilter(s3KeyFilter);
    s3KeyFilter.withFilterRules(new FilterRule().withName("suffix").withValue(".war"),
            new FilterRule().withName("prefix").withValue("deployables"));
    lambdaConfiguration.setFilter(notificationFilter);
    configurations.put("warUploaded", lambdaConfiguration);
    notificationConfiguration.setConfigurations(configurations);
    final SetBucketNotificationConfigurationRequest setBucketNotificationConfigurationRequest = new SetBucketNotificationConfigurationRequest(
            bucketName, notificationConfiguration);
    amazonS3Client.setBucketNotificationConfiguration(setBucketNotificationConfigurationRequest);

}

From source file:io.konig.maven.CreateAwsS3BucketAction.java

License:Apache License

public AwsDeployment from(String path) throws Exception {
    String cfTemplatePresent = System.getProperty("cfTemplatePresent");
    if (cfTemplatePresent == null || cfTemplatePresent.equals("N")) {
        try {//from  w ww.j a  v  a  2s  . co m
            File file = deployment.file(path);
            ObjectMapper mapper = new ObjectMapper();
            S3Bucket bucket = mapper.readValue(file, S3Bucket.class);
            deployment.verifyAWSCredentials();
            Regions regions = Regions.fromName(bucket.getRegion());
            AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(deployment.getCredential())
                    .withRegion(regions).build();
            String envtName = "";
            if (System.getProperty("environmentName") != null) {
                envtName = System.getProperty("environmentName");
            }
            String bucketName = StringUtils.replaceOnce(bucket.getBucketName(), "${environmentName}", envtName);
            Bucket b = s3client.createBucket(bucketName);

            if (bucket.getNotificationConfiguration() != null) {
                NotificationConfiguration notificationConfiguration = bucket.getNotificationConfiguration();
                if (notificationConfiguration.getTopicConfiguration() != null) {
                    TopicConfiguration topicConfiguration = notificationConfiguration.getTopicConfiguration();
                    BucketNotificationConfiguration s3notificationConfiguration = new BucketNotificationConfiguration();
                    String accountId = "";
                    if (System.getProperty("aws-account-id") != null) {
                        accountId = System.getProperty("aws-account-id");
                    }
                    String topicArn = StringUtils.replaceOnce(topicConfiguration.getTopicArn(),
                            "${aws-account-id}", accountId);
                    com.amazonaws.services.s3.model.TopicConfiguration topicConfig = new com.amazonaws.services.s3.model.TopicConfiguration(
                            topicArn, topicConfiguration.getEventType());
                    s3notificationConfiguration.addConfiguration("snsTopicConfig", topicConfig);

                    s3client.setBucketNotificationConfiguration(bucketName, s3notificationConfiguration);
                }
            }
            if (b != null)
                deployment.setResponse("AWS S3 Bucket is created ::" + b.getName());
        } catch (Exception e) {
            throw e;
        }
    } else {
        deployment.setResponse("S3 Bucket will be created through cloud formation template");
    }
    return deployment;
}