Example usage for com.amazonaws.services.sns AmazonSNS setTopicAttributes

List of usage examples for com.amazonaws.services.sns AmazonSNS setTopicAttributes

Introduction

In this page you can find the example usage for com.amazonaws.services.sns AmazonSNS setTopicAttributes.

Prototype

SetTopicAttributesResult setTopicAttributes(SetTopicAttributesRequest setTopicAttributesRequest);

Source Link

Document

Allows a topic owner to set an attribute of the topic to a new value.

Usage

From source file:com.netflix.spinnaker.clouddriver.aws.lifecycle.InstanceTerminationLifecycleAgent.java

License:Apache License

private static String ensureTopicExists(AmazonSNS amazonSNS, ARN topicARN, List<String> allAccountIds,
        ARN queueARN) {/*from w  w w. j a v a2  s.  com*/
    topicARN.arn = amazonSNS.createTopic(topicARN.name).getTopicArn();

    amazonSNS.setTopicAttributes(new SetTopicAttributesRequest().withTopicArn(topicARN.arn)
            .withAttributeName("Policy").withAttributeValue(buildSNSPolicy(topicARN, allAccountIds).toJson()));

    amazonSNS.subscribe(topicARN.arn, "sqs", queueARN.arn);

    return topicARN.arn;
}

From source file:com.netflix.spinnaker.clouddriver.aws.lifecycle.LaunchFailureNotificationAgent.java

License:Apache License

/**
 * Ensure that the topic exists and has a policy granting all accounts permission to publish messages to it
 *//* www  .j  a v a 2 s.c  o m*/
private static String ensureTopicExists(AmazonSNS amazonSNS, ARN topicARN, List<String> allAccountIds,
        ARN queueARN) {
    topicARN.arn = amazonSNS.createTopic(topicARN.name).getTopicArn();

    amazonSNS.setTopicAttributes(new SetTopicAttributesRequest().withTopicArn(topicARN.arn)
            .withAttributeName("Policy").withAttributeValue(buildSNSPolicy(topicARN, allAccountIds).toJson()));

    amazonSNS.subscribe(topicARN.arn, "sqs", queueARN.arn);

    return topicARN.arn;
}

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 {/*w w  w.jav  a 2 s .c om*/
            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;
}