Example usage for com.amazonaws.services.sns AmazonSNSClientBuilder standard

List of usage examples for com.amazonaws.services.sns AmazonSNSClientBuilder standard

Introduction

In this page you can find the example usage for com.amazonaws.services.sns AmazonSNSClientBuilder standard.

Prototype

public static AmazonSNSClientBuilder standard() 

Source Link

Usage

From source file:ca.paullalonde.gocd.sns_plugin.executors.StageStatusRequestExecutor.java

License:Apache License

private AmazonSNS makeSns(PluginSettings pluginSettings) throws Exception {
    String region = pluginSettings.getRegion();
    String awsAccessId = pluginSettings.getAwsAccessId();
    String awsSecretId = pluginSettings.getAwsSecretAccessId();
    AmazonSNSClientBuilder builder = AmazonSNSClientBuilder.standard();

    if ((region != null) && !region.isEmpty()) {
        builder = builder.withRegion(region);
    }/*from  w  w  w  .  jav  a  2  s  .  c  o m*/

    if ((awsAccessId != null) && !awsAccessId.isEmpty() && (awsSecretId != null) && !awsSecretId.isEmpty()) {
        BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsAccessId, awsSecretId);
        builder = builder.withCredentials(new AWSStaticCredentialsProvider(awsCreds));
    }

    return builder.build();
}

From source file:com.netflix.spinnaker.echo.pubsub.amazon.SQSSubscriberProvider.java

License:Apache License

@PostConstruct
public void start() {
    if (properties == null) {
        return;/*from ww w . j a v a 2 s .co  m*/
    }

    ExecutorService executorService = Executors.newFixedThreadPool(properties.getSubscriptions().size());

    List<PubsubSubscriber> subscribers = new ArrayList<>();

    properties.getSubscriptions().forEach((AmazonPubsubProperties.AmazonPubsubSubscription subscription) -> {
        log.info("Bootstrapping SQS for SNS topic: {}", subscription.getTopicARN());
        if (subscription.getTemplatePath() != null && !subscription.getTemplatePath().equals("")) {
            log.info("Using template: {} for subscription: {}", subscription.getTemplatePath(),
                    subscription.getName());
        }

        ARN queueArn = new ARN(subscription.getQueueARN());

        SQSSubscriber worker = new SQSSubscriber(objectMapper, subscription, pubsubMessageHandler,
                AmazonSNSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                () -> enabled.get(), registry);

        try {
            executorService.submit(worker);
            subscribers.add(worker);
            log.debug("Created worker for subscription: {}", subscription.getName());
        } catch (RejectedExecutionException e) {
            log.error("Could not start " + worker.getWorkerName(), e);
        }
    });
    pubsubSubscribers.putAll(subscribers);
}

From source file:com.netflix.spinnaker.echo.pubsub.aws.SQSSubscriberProvider.java

License:Apache License

@PostConstruct
public void start() {
    if (properties == null) {
        return;// ww w .j ava2  s  . com
    }

    ExecutorService executorService = Executors.newFixedThreadPool(properties.getSubscriptions().size());

    List<PubsubSubscriber> subscribers = new ArrayList<>();

    properties.getSubscriptions().forEach((AmazonPubsubProperties.AmazonPubsubSubscription subscription) -> {
        log.info("Bootstrapping SQS for SNS topic: {}", subscription.getTopicARN());
        if (subscription.getTemplatePath() != null && !subscription.getTemplatePath().equals("")) {
            log.info("Using template: {} for subscription: {}", subscription.getTemplatePath(),
                    subscription.getName());
        }

        ARN queueArn = new ARN(subscription.getQueueARN());

        SQSSubscriber worker = new SQSSubscriber(objectMapper, subscription, pubsubMessageHandler,
                AmazonSNSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                enabled::get, registry, jinjavaFactory, applicationEventPublisher);

        try {
            executorService.submit(worker);
            subscribers.add(worker);
            log.debug("Created worker for subscription: {}", subscription.getName());
        } catch (RejectedExecutionException e) {
            log.error("Could not start " + worker.getWorkerName(), e);
        }
    });
    pubsubSubscribers.putAll(subscribers);
}

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

License:Apache License

public AwsDeployment from(String path) throws Exception {
    String cfTemplatePresent = System.getProperty("cfTemplatePresent");
    if (cfTemplatePresent == null || cfTemplatePresent.equals("N")) {
        try {/*from ww w  . java 2 s.  co  m*/
            File file = deployment.file(path);
            ObjectMapper mapper = new ObjectMapper();
            S3Bucket bucket = mapper.readValue(file, S3Bucket.class);
            deployment.verifyAWSCredentials();
            String envtName = "";
            if (System.getProperty("environmentName") != null) {
                envtName = System.getProperty("environmentName");
            }
            String bucketName = StringUtils.replaceOnce(bucket.getBucketName(), "${environmentName}", envtName);
            TopicConfiguration notificationConfig = bucket.getNotificationConfiguration()
                    .getTopicConfiguration();
            if (notificationConfig != null && notificationConfig.getTopic() != null) {
                Topic topic = notificationConfig.getTopic();
                Regions regions = Regions.fromName(topic.getRegion());
                AmazonSNS sns = AmazonSNSClientBuilder.standard().withCredentials(deployment.getCredential())
                        .withRegion(regions).build();
                CreateTopicResult result = sns.createTopic(topic.getResourceName());
                deployment.setResponse("Topic with ARN : " + result.getTopicArn() + " is created");

                Policy policy = new Policy().withStatements(new Statement(Effect.Allow)
                        .withPrincipals(Principal.AllUsers).withActions(SNSActions.Publish)
                        .withResources(new Resource(result.getTopicArn()))
                        .withConditions(new ArnCondition(ArnComparisonType.ArnEquals,
                                ConditionFactory.SOURCE_ARN_CONDITION_KEY, "arn:aws:s3:*:*:" + bucketName)));

                sns.setTopicAttributes(
                        new SetTopicAttributesRequest(result.getTopicArn(), "Policy", policy.toJson()));
            } else {
                deployment.setResponse("No topic is configured to the S3 Bucket");
            }

        } catch (Exception e) {
            throw e;
        }
    } else {
        deployment.setResponse("Topic will be created through cloud formation template");
    }
    return deployment;
}

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

License:Apache License

public AwsDeployment from(String path) throws Exception {
    String cfTemplatePresent = System.getProperty("cfTemplatePresent");
    if (cfTemplatePresent == null || cfTemplatePresent.equals("N")) {
        try {//  w  w w.j  ava 2  s . c  o  m
            File file = deployment.file(path);
            ObjectMapper mapper = new ObjectMapper();
            S3Bucket bucket = mapper.readValue(file, S3Bucket.class);
            deployment.verifyAWSCredentials();

            QueueConfiguration queueConfig = bucket.getNotificationConfiguration().getQueueConfiguration();

            if (queueConfig != null && queueConfig.getQueue() != null) {
                String accountId = "";
                if (System.getProperty("aws-account-id") != null) {
                    accountId = System.getProperty("aws-account-id");
                }

                Queue queue = queueConfig.getQueue();
                Regions regions = Regions.fromName(queue.getRegion());
                AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(deployment.getCredential())
                        .withRegion(regions).build();
                AmazonSNS sns = AmazonSNSClientBuilder.standard().withCredentials(deployment.getCredential())
                        .withRegion(regions).build();

                CreateQueueResult result = sqs.createQueue(queue.getResourceName());

                String topicArn = StringUtils.replaceOnce(
                        bucket.getNotificationConfiguration().getTopicConfiguration().getTopicArn(),
                        "${aws-account-id}", accountId);
                String queueArn = StringUtils.replaceOnce(
                        bucket.getNotificationConfiguration().getQueueConfiguration().getQueueArn(),
                        "${aws-account-id}", accountId);

                deployment.setResponse("Queue  " + queueArn + " is created");

                Policy policy = new Policy()
                        .withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers)
                                .withActions(SQSActions.SendMessage).withResources(new Resource(queueArn))
                                .withConditions(ConditionFactory.newSourceArnCondition(topicArn)));

                Map<String, String> queueAttributes = new HashMap<String, String>();
                queueAttributes.put(QueueAttributeName.Policy.toString(), policy.toJson());

                deployment.setResponse("Queue Policy Configured : " + policy.toJson());

                sqs.setQueueAttributes(new SetQueueAttributesRequest(result.getQueueUrl(), queueAttributes));

                Topics.subscribeQueue(sns, sqs, topicArn, result.getQueueUrl());

                deployment.setResponse(
                        "Subscription is created : Topic [" + topicArn + "], Queue [" + queueArn + "]");
            } else {
                deployment.setResponse("Queue Configuration Failed");
            }

        } catch (Exception e) {
            throw e;
        }
    } else {
        deployment.setResponse("Queue will be created through cloud formation template");
    }
    return deployment;
}

From source file:io.konig.maven.DeleteAwsSNS.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  w  w. ja  v a 2 s. c  o m*/
            File file = deployment.file(path);
            ObjectMapper mapper = new ObjectMapper();
            S3Bucket bucket = mapper.readValue(file, S3Bucket.class);
            deployment.verifyAWSCredentials();
            TopicConfiguration notificationConfig = bucket.getNotificationConfiguration()
                    .getTopicConfiguration();
            if (notificationConfig != null && notificationConfig.getTopic() != null) {
                Topic topic = notificationConfig.getTopic();
                Regions regions = Regions.fromName(topic.getRegion());
                AmazonSNS sns = AmazonSNSClientBuilder.standard().withCredentials(deployment.getCredential())
                        .withRegion(regions).build();
                String accountId = "";
                if (System.getProperty("aws-account-id") != null) {
                    accountId = System.getProperty("aws-account-id");
                }
                String topicArn = StringUtils.replaceOnce(notificationConfig.getTopicArn(), "${aws-account-id}",
                        accountId);
                sns.deleteTopic(topicArn);
                deployment.setResponse("Topic with ARN : " + topicArn + " is deleted");
            } else {
                deployment.setResponse("No topic is configured to the S3 Bucket");
            }

        } catch (Exception e) {
            throw e;
        }
    } else {
        deployment.setResponse("Topic will be deleted through cloud formation stack");
    }
    return deployment;
}

From source file:org.apache.beam.sdk.io.aws.sns.BasicSnsProvider.java

License:Apache License

@Override
public AmazonSNS createSnsPublisher() {
    return AmazonSNSClientBuilder.standard().withCredentials(getCredentialsProvider()).withRegion(region)
            .build();
}

From source file:org.finra.herd.dao.AwsClientFactory.java

License:Apache License

/**
 * Creates a client for accessing Amazon SNS.
 *
 * @param awsParamsDto the AWS related parameters DTO that includes optional proxy information
 *
 * @return the Amazon SNS client/* w  ww . j a  v  a2  s  .c o m*/
 */
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public AmazonSNS getAmazonSNSClient(AwsParamsDto awsParamsDto) {
    // Construct and return a new client to invoke service methods on Amazon SNS using default credentials provider chain.
    return AmazonSNSClientBuilder.standard()
            .withClientConfiguration(awsHelper.getClientConfiguration(awsParamsDto))
            .withRegion(awsParamsDto.getAwsRegionName()).build();
}

From source file:org.lendingclub.mercator.aws.SNSScanner.java

License:Apache License

@Override
protected AmazonSNSClient createClient() {
    return (AmazonSNSClient) builder.configure(AmazonSNSClientBuilder.standard()).build();
}

From source file:org.wildfly.camel.test.common.aws.SNSUtils.java

License:Apache License

public static AmazonSNSClient createNotificationClient() {
    BasicCredentialsProvider credentials = BasicCredentialsProvider.standard();
    AmazonSNSClient client = !credentials.isValid() ? null
            : (AmazonSNSClient) AmazonSNSClientBuilder.standard().withCredentials(credentials)
                    .withRegion("eu-west-1").build();
    return client;
}