Skip to content

Commit 3bdad1e

Browse files
authored
Merge pull request #1475 from scmacdon/master
Update Forecast and Firehose Java V2 Examples
2 parents 86a84ee + c9655cd commit 3bdad1e

21 files changed

+1385
-1482
lines changed

javav2/example_code/firehose/Readme.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This README discusses how to run and test the Java code examples for Amazon Kine
88

99
The Java examples perform AWS operations for the account and AWS Region for which you've specified credentials, and you may incur AWS service charges by running them. See the [AWS Pricing page](https://aws.amazon.com/pricing/) for details about the charges you can expect for a given service and operation.
1010

11-
Some of these examples perform *destructive* operations on AWS resources, such as deleting a rule by running the **DeleteRule** example. **Be very careful** when running an operation that deletes or modifies AWS resources in your account. It's best to create separate test-only resources when experimenting with these examples.
11+
Some of these examples perform *destructive* operations on AWS resources, such as deleting a rule by running the **DeleteStream** example. **Be very careful** when running an operation that deletes or modifies AWS resources in your account. It's best to create separate test-only resources when experimenting with these examples.
1212

1313
To run these examples, you'll need the AWS SDK for Java libraries in your **CLASSPATH**.
1414

@@ -18,12 +18,12 @@ Here **/path/to/aws-java-sdk/<jar-file-name>.jar** is the path to where you extr
1818

1919
For systems with Bash support, once you set the **CLASSPATH**, you can run a particular example as follows.
2020

21-
java com.example.eventbridge.ListRules
21+
java com.example.firehose.ListDeliveryStreams
2222

2323

24-
## Testing the EventBridge Java files
24+
## Testing the Amazon Kinesis Data Firehose Java files
2525

26-
You can test the Java code examples for EventBridge by running a test file named **AmazonEventBridgeServiceIntegrationTest**. This file uses JUnit 5 to run the JUnit tests and is located in the **src/test/java** folder. For more information, see [https://junit.org/junit5/](https://junit.org/junit5/).
26+
You can test the Java code examples for Kinesis Data Firehose by running a test file named **FirehoseTest**. This file uses JUnit 5 to run the JUnit tests and is located in the **src/test/java** folder. For more information, see [https://junit.org/junit5/](https://junit.org/junit5/).
2727

2828
You can run the JUnit tests from a Java IDE, such as IntelliJ, or from the command line by using Maven. As each test runs, you can view messages that inform you if the various tests succeed or fail. For example, the following message informs you that Test 3 passed.
2929

@@ -32,11 +32,15 @@ You can run the JUnit tests from a Java IDE, such as IntelliJ, or from the comma
3232
**WARNING**: _Running these JUnit tests manipulates real Amazon resources and may incur charges on your account._
3333

3434
### Properties file
35-
Before running the Amazon EventBridge tests, you must define values in the **config.properties** file located in the **resources** folder. This file contains values that are required to run the JUnit tests. For example, you define a delivery stream name used in the tests. If you do not define all values, the JUnit tests fail.
35+
Before running the Amazon Kinesis Data Firehose tests, you must define values in the **config.properties** file located in the **resources** folder. This file contains values that are required to run the JUnit tests. For example, you define a delivery stream name used in the tests. If you do not define all values, the JUnit tests fail.
3636

3737
Define this value to successfully run the JUnit tests:
3838

39-
- **ruleName** - The rule name.
39+
- **bucketARN** - The ARN of the Amazon S3 bucket where the data stream is written.
40+
-**roleARN** - The ARN of the IAM role that has the permissions that Kinesis Data Firehose needs.
41+
-**newStream** - The name of the delivery stream.
42+
- **existingStream** - The name of an existing stream.
43+
- **textValue** - The text used as the data to write to the data stream.
4044

4145

4246
### Command line
@@ -49,7 +53,7 @@ You will see output from the JUnit tests, as shown here.
4953
[INFO] -------------------------------------------------------
5054
[INFO] T E S T S
5155
[INFO] -------------------------------------------------------
52-
[INFO] Running AmazonEventBridgeServiceIntegrationTest
56+
[INFO] Running FirehoseTest
5357
Test 1 passed
5458
Test 2 passed
5559
...

javav2/example_code/firehose/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ files:
2121
- path: src/main/java/com/example/firehose/StockTradeGenerator.java
2222
services:
2323
- firehose
24-
- path: src/test/java/AmazonFirehoseServiceIntegrationTest.java
24+
- path: src/test/java/FirehoseTest.java
2525
services:
2626
- firehose
Lines changed: 81 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,81 @@
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+
}
Lines changed: 66 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,66 @@
1-
//snippet-sourcedescription:[DeleteStream.java demonstrates how to delete 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.delete_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.DeleteDeliveryStreamRequest;
27-
// snippet-end:[firehose.java2.delete_stream.import]
28-
29-
public class DeleteStream {
30-
31-
public static void main(String[] args) {
32-
33-
final String USAGE = "\n" +
34-
"Usage:\n" +
35-
" DeleteStream <streamName> \n\n" +
36-
"Where:\n" +
37-
" streamName - The delivery stream name \n";
38-
39-
if (args.length < 1) {
40-
System.out.println(USAGE);
41-
System.exit(1);
42-
}
43-
44-
String streamName = args[0];
45-
46-
Region region = Region.US_WEST_2;
47-
FirehoseClient firehoseClient = FirehoseClient.builder()
48-
.region(region)
49-
.build();
50-
51-
delStream(firehoseClient, streamName) ;
52-
}
53-
54-
// snippet-start:[firehose.java2.delete_stream.main]
55-
public static void delStream(FirehoseClient firehoseClient, String streamName) {
56-
57-
try {
58-
DeleteDeliveryStreamRequest deleteDeliveryStreamRequest = DeleteDeliveryStreamRequest.builder()
59-
.deliveryStreamName(streamName)
60-
.build();
61-
62-
firehoseClient.deleteDeliveryStream(deleteDeliveryStreamRequest);
63-
System.out.println("Delivery stream "+streamName +" is deleted");
64-
65-
} catch (FirehoseException e) {
66-
System.out.println(e.getLocalizedMessage());
67-
System.exit(1);
68-
}
69-
// snippet-end:[firehose.java2.delete_stream.main]
70-
}
71-
}
1+
//snippet-sourcedescription:[DeleteStream.java demonstrates how to delete 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.delete_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.DeleteDeliveryStreamRequest;
21+
// snippet-end:[firehose.java2.delete_stream.import]
22+
23+
public class DeleteStream {
24+
25+
public static void main(String[] args) {
26+
27+
final String USAGE = "\n" +
28+
"Usage:\n" +
29+
" DeleteStream <streamName> \n\n" +
30+
"Where:\n" +
31+
" streamName - the data stream name to delete. \n";
32+
33+
if (args.length != 1) {
34+
System.out.println(USAGE);
35+
System.exit(1);
36+
}
37+
38+
String streamName = args[0];
39+
Region region = Region.US_WEST_2;
40+
FirehoseClient firehoseClient = FirehoseClient.builder()
41+
.region(region)
42+
.build();
43+
44+
delStream(firehoseClient, streamName) ;
45+
firehoseClient.close();
46+
}
47+
48+
// snippet-start:[firehose.java2.delete_stream.main]
49+
public static void delStream(FirehoseClient firehoseClient, String streamName) {
50+
51+
try {
52+
DeleteDeliveryStreamRequest deleteDeliveryStreamRequest = DeleteDeliveryStreamRequest.builder()
53+
.deliveryStreamName(streamName)
54+
.build();
55+
56+
firehoseClient.deleteDeliveryStream(deleteDeliveryStreamRequest);
57+
System.out.println("Delivery Stream "+streamName +" is deleted");
58+
59+
} catch (FirehoseException e) {
60+
System.out.println(e.getLocalizedMessage());
61+
System.exit(1);
62+
}
63+
// snippet-end:[firehose.java2.delete_stream.main]
64+
}
65+
}
66+

0 commit comments

Comments
 (0)