|
1 |
| -//snippet-sourcedescription:[CreateDeliveryStream.java demonstrates how to create a delivery stream.] |
2 |
| -//snippet-keyword:[SDK for Java 2.0] |
3 |
| -//snippet-keyword:[Code Sample] |
4 |
| -//snippet-service:[Amazon Kinesis Data Firehose] |
5 |
| -//snippet-sourcetype:[full-example] |
6 |
| -//snippet-sourcedate:[7/6/2020] |
7 |
| -//snippet-sourceauthor:[scmacdon - aws] |
8 |
| - |
9 |
| -/* |
10 |
| - Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
11 |
| - This file is licensed under the Apache License, Version 2.0 (the "License"). |
12 |
| - You may not use this file except in compliance with the License. A copy of |
13 |
| - the License is located at |
14 |
| - http://aws.amazon.com/apache2.0/ |
15 |
| - This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
16 |
| - CONDITIONS OF ANY KIND, either express or implied. See the License for the |
17 |
| - specific language governing permissions and limitations under the License. |
18 |
| -*/ |
19 |
| - |
20 |
| -package com.example.firehose; |
21 |
| - |
22 |
| -// snippet-start:[firehose.java2.create_stream.import] |
23 |
| -import software.amazon.awssdk.regions.Region; |
24 |
| -import software.amazon.awssdk.services.firehose.FirehoseClient; |
25 |
| -import software.amazon.awssdk.services.firehose.model.FirehoseException; |
26 |
| -import software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamRequest; |
27 |
| -import software.amazon.awssdk.services.firehose.model.ExtendedS3DestinationConfiguration; |
28 |
| -import software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamResponse; |
29 |
| -// snippet-end:[firehose.java2.create_stream.import] |
30 |
| - |
31 |
| -public class CreateDeliveryStream { |
32 |
| - |
33 |
| - public static void main(String[] args) { |
34 |
| - |
35 |
| - final String USAGE = "\n" + |
36 |
| - "Usage:\n" + |
37 |
| - " CreateDeliveryStream <bucketARN> <roleARN> <streamName> \n\n" + |
38 |
| - "Where:\n" + |
39 |
| - " bucketARN - The Amazon Resource Name (ARN) of the bucket where the delivery stream is written \n\n" + |
40 |
| - " roleARN - The ARN of the role that has the permissions that Amazon Kinesis Data Firehose needs \n" + |
41 |
| - " streamName - The delivery stream name \n"; |
42 |
| - |
43 |
| - if (args.length < 3) { |
44 |
| - System.out.println(USAGE); |
45 |
| - System.exit(1); |
46 |
| - } |
47 |
| - |
48 |
| - String bucketARN = args[0]; |
49 |
| - String roleARN = args[1]; |
50 |
| - String streamName = args[2]; |
51 |
| - |
52 |
| - Region region = Region.US_WEST_2; |
53 |
| - FirehoseClient firehoseClient = FirehoseClient.builder() |
54 |
| - .region(region) |
55 |
| - .build(); |
56 |
| - |
57 |
| - createStream(firehoseClient, bucketARN, roleARN, streamName) ; |
58 |
| - } |
59 |
| - |
60 |
| - // snippet-start:[firehose.java2.create_stream.main] |
61 |
| - public static void createStream(FirehoseClient firehoseClient, String bucketARN, String roleARN, String streamName) { |
62 |
| - |
63 |
| - try { |
64 |
| - |
65 |
| - ExtendedS3DestinationConfiguration destinationConfiguration = ExtendedS3DestinationConfiguration.builder() |
66 |
| - .bucketARN(bucketARN) |
67 |
| - .roleARN(roleARN) |
68 |
| - .build(); |
69 |
| - |
70 |
| - CreateDeliveryStreamRequest deliveryStreamRequest = CreateDeliveryStreamRequest.builder() |
71 |
| - .deliveryStreamName(streamName) |
72 |
| - .extendedS3DestinationConfiguration(destinationConfiguration) |
73 |
| - .deliveryStreamType("DirectPut") |
74 |
| - .build(); |
75 |
| - |
76 |
| - CreateDeliveryStreamResponse streamResponse = firehoseClient.createDeliveryStream(deliveryStreamRequest); |
77 |
| - |
78 |
| - System.out.println("Delivery stream ARN is "+streamResponse.deliveryStreamARN()); |
79 |
| - |
80 |
| - } catch (FirehoseException e) { |
81 |
| - System.out.println(e.getLocalizedMessage()); |
82 |
| - System.exit(1); |
83 |
| - } |
84 |
| - // snippet-end:[firehose.java2.create_stream.main] |
85 |
| - } |
86 |
| -} |
| 1 | +//snippet-sourcedescription:[CreateDeliveryStream.java demonstrates how to create a delivery stream.] |
| 2 | +//snippet-keyword:[AWS SDK for Java v2] |
| 3 | +//snippet-keyword:[Code Sample] |
| 4 | +//snippet-service:[Amazon Kinesis Data Firehose] |
| 5 | +//snippet-sourcetype:[full-example] |
| 6 | +//snippet-sourcedate:[11/04/2020] |
| 7 | +//snippet-sourceauthor:[scmacdon - aws] |
| 8 | + |
| 9 | +/* |
| 10 | + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 11 | + SPDX-License-Identifier: Apache-2.0 |
| 12 | +*/ |
| 13 | + |
| 14 | +package com.example.firehose; |
| 15 | + |
| 16 | +// snippet-start:[firehose.java2.create_stream.import] |
| 17 | +import software.amazon.awssdk.regions.Region; |
| 18 | +import software.amazon.awssdk.services.firehose.FirehoseClient; |
| 19 | +import software.amazon.awssdk.services.firehose.model.FirehoseException; |
| 20 | +import software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamRequest; |
| 21 | +import software.amazon.awssdk.services.firehose.model.ExtendedS3DestinationConfiguration; |
| 22 | +import software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamResponse; |
| 23 | +// snippet-end:[firehose.java2.create_stream.import] |
| 24 | + |
| 25 | +public class CreateDeliveryStream { |
| 26 | + |
| 27 | + public static void main(String[] args) { |
| 28 | + |
| 29 | + final String USAGE = "\n" + |
| 30 | + "Usage:\n" + |
| 31 | + " CreateDeliveryStream <bucketARN> <roleARN> <streamName> \n\n" + |
| 32 | + "Where:\n" + |
| 33 | + " bucketARN - the ARN of the Amazon S3 bucket where the data stream is written. \n\n" + |
| 34 | + " roleARN - the ARN of the IAM role that has the permissions that Kinesis Data Firehose needs. \n" + |
| 35 | + " streamName - the name of the delivery stream. \n"; |
| 36 | + |
| 37 | + if (args.length != 3) { |
| 38 | + System.out.println(USAGE); |
| 39 | + System.exit(1); |
| 40 | + } |
| 41 | + |
| 42 | + String bucketARN = args[0]; |
| 43 | + String roleARN = args[1]; |
| 44 | + String streamName = args[2]; |
| 45 | + |
| 46 | + Region region = Region.US_WEST_2; |
| 47 | + FirehoseClient firehoseClient = FirehoseClient.builder() |
| 48 | + .region(region) |
| 49 | + .build(); |
| 50 | + |
| 51 | + createStream(firehoseClient, bucketARN, roleARN, streamName) ; |
| 52 | + firehoseClient.close(); |
| 53 | + } |
| 54 | + |
| 55 | + // snippet-start:[firehose.java2.create_stream.main] |
| 56 | + public static void createStream(FirehoseClient firehoseClient, String bucketARN, String roleARN, String streamName) { |
| 57 | + |
| 58 | + try { |
| 59 | + |
| 60 | + ExtendedS3DestinationConfiguration destinationConfiguration = ExtendedS3DestinationConfiguration.builder() |
| 61 | + .bucketARN(bucketARN) |
| 62 | + .roleARN(roleARN) |
| 63 | + .build(); |
| 64 | + |
| 65 | + CreateDeliveryStreamRequest deliveryStreamRequest = CreateDeliveryStreamRequest.builder() |
| 66 | + .deliveryStreamName(streamName) |
| 67 | + .extendedS3DestinationConfiguration(destinationConfiguration) |
| 68 | + .deliveryStreamType("DirectPut") |
| 69 | + .build(); |
| 70 | + |
| 71 | + CreateDeliveryStreamResponse streamResponse = firehoseClient.createDeliveryStream(deliveryStreamRequest); |
| 72 | + |
| 73 | + System.out.println("Delivery Stream ARN is "+streamResponse.deliveryStreamARN()); |
| 74 | + |
| 75 | + } catch (FirehoseException e) { |
| 76 | + System.out.println(e.getLocalizedMessage()); |
| 77 | + System.exit(1); |
| 78 | + } |
| 79 | + // snippet-end:[firehose.java2.create_stream.main] |
| 80 | + } |
| 81 | +} |
0 commit comments