use of com.amazonaws.services.s3.model.BucketNotificationConfiguration in project aws-doc-sdk-examples by awsdocs.
the class EnableNotificationOnABucket method main.
public static void main(String[] args) throws IOException {
String bucketName = "*** Bucket name ***";
Regions clientRegion = Regions.DEFAULT_REGION;
String snsTopicARN = "*** SNS Topic ARN ***";
String sqsQueueARN = "*** SQS Queue ARN ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(clientRegion).build();
BucketNotificationConfiguration notificationConfiguration = new BucketNotificationConfiguration();
// Add an SNS topic notification.
notificationConfiguration.addConfiguration("snsTopicConfig", new TopicConfiguration(snsTopicARN, EnumSet.of(S3Event.ObjectCreated)));
// Add an SQS queue notification.
notificationConfiguration.addConfiguration("sqsQueueConfig", new QueueConfiguration(sqsQueueARN, EnumSet.of(S3Event.ObjectCreated)));
// Create the notification configuration request and set the bucket notification configuration.
SetBucketNotificationConfigurationRequest request = new SetBucketNotificationConfigurationRequest(bucketName, notificationConfiguration);
s3Client.setBucketNotificationConfiguration(request);
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
use of com.amazonaws.services.s3.model.BucketNotificationConfiguration in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method convertToXmlByteArray.
/**
* Converts the specified notification configuration into an XML byte array.
*
* @param notificationConfiguration The configuration to convert.
* @return The XML byte array representation.
*/
public byte[] convertToXmlByteArray(BucketNotificationConfiguration notificationConfiguration) {
final XmlWriter xml = new XmlWriter();
xml.start("NotificationConfiguration", "xmlns", Constants.XML_NAMESPACE);
final Map<String, NotificationConfiguration> configurations = notificationConfiguration.getConfigurations();
for (final Map.Entry<String, NotificationConfiguration> entry : configurations.entrySet()) {
final String configName = entry.getKey();
final NotificationConfiguration config = entry.getValue();
if (config instanceof TopicConfiguration) {
xml.start("TopicConfiguration");
xml.start("Id").value(configName).end();
xml.start("Topic").value(((TopicConfiguration) config).getTopicARN()).end();
addEventsAndFilterCriteria(xml, config);
xml.end();
} else if (config instanceof QueueConfiguration) {
xml.start("QueueConfiguration");
xml.start("Id").value(configName).end();
xml.start("Queue").value(((QueueConfiguration) config).getQueueARN()).end();
addEventsAndFilterCriteria(xml, config);
xml.end();
} else if (config instanceof CloudFunctionConfiguration) {
xml.start("CloudFunctionConfiguration");
xml.start("Id").value(configName).end();
xml.start("InvocationRole").value(((CloudFunctionConfiguration) config).getInvocationRoleARN()).end();
xml.start("CloudFunction").value(((CloudFunctionConfiguration) config).getCloudFunctionARN()).end();
addEventsAndFilterCriteria(xml, config);
xml.end();
} else if (config instanceof LambdaConfiguration) {
xml.start("CloudFunctionConfiguration");
xml.start("Id").value(configName).end();
xml.start("CloudFunction").value(((LambdaConfiguration) config).getFunctionARN()).end();
addEventsAndFilterCriteria(xml, config);
xml.end();
}
}
xml.end();
return xml.getBytes();
}
use of com.amazonaws.services.s3.model.BucketNotificationConfiguration in project aws-sdk-android by aws-amplify.
the class BucketNotificationConfigurationStaxUnmarshallerTest method unmarshall_ValidLambdaConfiguration.
@Test
public void unmarshall_ValidLambdaConfiguration() throws Exception {
final BucketNotificationConfiguration config = unmarshaller.unmarshall(getResource(LAMBDA_INPUT));
final LambdaConfiguration lambdaConfig = (LambdaConfiguration) config.getConfigurationByName("LambdaConfigId");
assertEquals("some-lambda-function-arn", lambdaConfig.getFunctionARN());
assertEventsUnmarshalledCorrectly(lambdaConfig.getEvents());
assertFilterRulesUnmarshalledCorrectly(lambdaConfig.getFilter().getS3KeyFilter().getFilterRules());
}
use of com.amazonaws.services.s3.model.BucketNotificationConfiguration in project aws-sdk-android by aws-amplify.
the class BucketNotificationConfigurationStaxUnmarshallerTest method unmarshall_ValidCloudFunctionConfiguration.
/**
* If CloudFunctionConfiguration has the InvocationRole attribute it should be unmarshalled into
* a {@link CloudFunctionConfiguration}
*/
@Test
public void unmarshall_ValidCloudFunctionConfiguration() throws Exception {
final BucketNotificationConfiguration config = unmarshaller.unmarshall(getResource(CLOUD_FUNCTION_INPUT));
final CloudFunctionConfiguration cloudFunctionConfig = (CloudFunctionConfiguration) config.getConfigurationByName("CloudFunctionConfigId");
assertEquals("some-cloud-function-arn", cloudFunctionConfig.getCloudFunctionARN());
assertEquals("some-cloud-invoc-role", cloudFunctionConfig.getInvocationRoleARN());
assertEventsUnmarshalledCorrectly(cloudFunctionConfig.getEvents());
assertFilterRulesUnmarshalledCorrectly(cloudFunctionConfig.getFilter().getS3KeyFilter().getFilterRules());
}
use of com.amazonaws.services.s3.model.BucketNotificationConfiguration in project aws-sdk-android by aws-amplify.
the class BucketNotificationConfigurationStaxUnmarshallerTest method unmarshall_ValidTopicConfiguration.
@Test
public void unmarshall_ValidTopicConfiguration() throws Exception {
final BucketNotificationConfiguration config = unmarshaller.unmarshall(getResource(TOPIC_INPUT));
final TopicConfiguration topicConfig = (TopicConfiguration) config.getConfigurationByName("TopicConfigId");
assertEquals("some-topic-arn", topicConfig.getTopicARN());
assertEventsUnmarshalledCorrectly(topicConfig.getEvents());
assertFilterRulesUnmarshalledCorrectly(topicConfig.getFilter().getS3KeyFilter().getFilterRules());
}
Aggregations