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;
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();
64  Properties flinkProperties = applicationProperties.get("FlinkApplicationProperties");
66  if (flinkProperties == null) {
67    throw new RuntimeException("Unable to load FlinkApplicationProperties properties from the runtime.");
68  }
70  parameter = ParameterToolUtils.fromApplicationProperties(flinkProperties);