Example usage for com.amazonaws.services.glacier.model VaultNotificationConfig withSNSTopic

List of usage examples for com.amazonaws.services.glacier.model VaultNotificationConfig withSNSTopic

Introduction

In this page you can find the example usage for com.amazonaws.services.glacier.model VaultNotificationConfig withSNSTopic.

Prototype


public VaultNotificationConfig withSNSTopic(String sNSTopic) 

Source Link

Document

The Amazon Simple Notification Service (Amazon SNS) topic Amazon Resource Name (ARN).

Usage

From source file:com.connexience.server.model.archive.glacier.SetupUtils.java

License:Open Source License

public static void setupVault(String accessKey, String secretKey, String domainName, String vaultName,
        String topicARN) {/* www  . j av a  2 s .  c  o m*/
    try {
        AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);

        AmazonGlacierClient amazonGlacierClient = new AmazonGlacierClient(awsCredentials);
        amazonGlacierClient.setEndpoint("https://glacier." + domainName + ".amazonaws.com/");

        CreateVaultRequest createVaultRequest = new CreateVaultRequest();
        createVaultRequest.withVaultName(vaultName);

        CreateVaultResult createVaultResult = amazonGlacierClient.createVault(createVaultRequest);
        if (createVaultResult != null) {
            VaultNotificationConfig vaultNotificationConfig = new VaultNotificationConfig();
            vaultNotificationConfig.withSNSTopic(topicARN);
            vaultNotificationConfig.withEvents("ArchiveRetrievalCompleted", "InventoryRetrievalCompleted");

            SetVaultNotificationsRequest setVaultNotificationsRequest = new SetVaultNotificationsRequest();
            setVaultNotificationsRequest.withVaultName(vaultName);
            setVaultNotificationsRequest.withVaultNotificationConfig(vaultNotificationConfig);

            amazonGlacierClient.setVaultNotifications(setVaultNotificationsRequest);
        } else
            logger.warn("Unable to create vault: \"" + vaultName + "\"");

        amazonGlacierClient.shutdown();
    } catch (AmazonServiceException amazonServiceException) {
        logger.warn("AmazonServiceException: " + amazonServiceException);
        logger.debug(amazonServiceException);
    } catch (IllegalArgumentException illegalArgumentException) {
        logger.warn("IllegalArgumentException: " + illegalArgumentException);
        logger.debug(illegalArgumentException);
    } catch (AmazonClientException amazonClientException) {
        logger.warn("AmazonClientException: " + amazonClientException);
        logger.debug(amazonClientException);
    } catch (Throwable throwable) {
        logger.warn("Throwable: " + throwable);
        logger.debug(throwable);
    }
}