Read parameters from Application Properties

Eventually, we’d like to deploy the program to KDA. However, instead of logging in to a cluster and directly submitting a job to the Flink runtime, you upload the respective fat JAR to Amazon S3 and start the execution by calling an API. So we don’t get access to the Flink cluster and we hence need to adapt the way we pass parameters to the Flink application.

If the Flink application is executed with Kinesis Data Analytics, we can obtain parameters from the Kinesis Analytics runtime. To this end, we can call the KinesisAnalyticsRuntime.getApplicationProperties() function to retrieve the parameters that are passed to the service through an API.

If the Flink application is executed in the local development environment, we continue to use the command line arguments that are specified when the main method is invoked.

55ParameterTool parameter;
56
57if (env instanceof LocalStreamEnvironment) {
58  //read the parameters specified from the command line args
59  parameter = ParameterTool.fromArgs(args);
60} else {
61  //read the parameters from the Kinesis Analytics environment
62  Map<String, Properties> applicationProperties = KinesisAnalyticsRuntime.getApplicationProperties();
63
64  Properties flinkProperties = applicationProperties.get("FlinkApplicationProperties");
65
66  if (flinkProperties == null) {
67    throw new RuntimeException("Unable to load FlinkApplicationProperties properties from the runtime.");
68  }
69
70  parameter = ParameterToolUtils.fromApplicationProperties(flinkProperties);
71}