Amazon Managed Service for Apache Flink¶
Amazon Managed Service for Apache Flink is a fully managed service that you can use to process and analyze streaming data using Java, Python, SQL, or Scala. The service enables you to quickly author and run Java, SQL, or Scala code against streaming sources to perform time series analytics, feed real-time dashboards, and create real-time metrics.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Create necessary resources using AWS Console or AWS CLI.
Install API libraries via pip.
pip install 'apache-airflow[amazon]'Detailed information is available Installation of Airflow®
Generic Parameters¶
- aws_conn_id
Reference to Amazon Web Services Connection ID. If this parameter is set to
None
then the default boto3 behaviour is used without a connection lookup. Otherwise use the credentials stored in the Connection. Default:aws_default
- region_name
AWS Region Name. If this parameter is set to
None
or omitted then region_name from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None
- verify
Whether or not to verify SSL certificates.
False
- Do not validate SSL certificates.path/to/cert/bundle.pem - A filename of the CA cert bundle to use. You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.
If this parameter is set to
None
or is omitted then verify from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None
- botocore_config
The provided dictionary is used to construct a botocore.config.Config. This configuration can be used to configure Avoid Throttling exceptions, timeouts, etc.
{ "signature_version": "unsigned", "s3": { "us_east_1_regional_endpoint": True, }, "retries": { "mode": "standard", "max_attempts": 10, }, "connect_timeout": 300, "read_timeout": 300, "tcp_keepalive": True, }
If this parameter is set to
None
or omitted then config_kwargs from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None
Note
Specifying an empty dictionary,
{}
, will overwrite the connection configuration for botocore.config.Config
Operators¶
Create an Amazon Managed Service for Apache Flink Application¶
To create an Amazon Managed Service for Apache Flink application, you can use
KinesisAnalyticsV2CreateApplicationOperator
.
tests/system/amazon/aws/example_kinesis_analytics.py
create_application = KinesisAnalyticsV2CreateApplicationOperator(
task_id="create_application",
application_name=application_name,
runtime_environment="FLINK-1_18",
service_execution_role=test_context[ROLE_ARN_KEY],
create_application_kwargs={
"ApplicationConfiguration": {
"FlinkApplicationConfiguration": {
"ParallelismConfiguration": {
"ConfigurationType": "CUSTOM",
"Parallelism": 2,
"ParallelismPerKPU": 1,
"AutoScalingEnabled": False,
}
},
"EnvironmentProperties": {
"PropertyGroups": [
{
"PropertyGroupId": "BlueprintMetadata",
"PropertyMap": {
"AWSRegion": region_name,
"BlueprintName": "KDS_FLINK-DATASTREAM-JAVA_S3",
"BucketName": f"s3://{bucket_name}/",
"PartitionFormat": "yyyy-MM-dd-HH",
"StreamInitialPosition": "TRIM_HORIZON",
"StreamName": stream_name,
},
},
]
},
"ApplicationCodeConfiguration": {
"CodeContent": {
"S3ContentLocation": {
"BucketARN": f"arn:aws:s3:::{bucket_name}",
"FileKey": "code/kds-to-s3-datastream-java-1.0.1.jar",
},
},
"CodeContentType": "ZIPFILE",
},
}
},
)
Start an Amazon Managed Service for Apache Flink Application¶
To start an Amazon Managed Service for Apache Flink application, you can use
KinesisAnalyticsV2StartApplicationOperator
.
tests/system/amazon/aws/example_kinesis_analytics.py
start_application = KinesisAnalyticsV2StartApplicationOperator(
task_id="start_application",
application_name=application_name,
)
Stop an Amazon Managed Service for Apache Flink Application¶
To stop an Amazon Managed Service for Apache Flink application, you can use
KinesisAnalyticsV2StopApplicationOperator
.
tests/system/amazon/aws/example_kinesis_analytics.py
stop_application = KinesisAnalyticsV2StopApplicationOperator(
task_id="stop_application",
application_name=application_name,
)
Sensors¶
Wait for an Amazon Managed Service for Apache Flink Application to start¶
To wait on the state of an Amazon Managed Service for Apache Flink Application to start you can use
KinesisAnalyticsV2StartApplicationCompletedSensor
.
tests/system/amazon/aws/example_kinesis_analytics.py
await_start_application = KinesisAnalyticsV2StartApplicationCompletedSensor(
task_id="await_start_application",
application_name=application_name,
)
Wait for an Amazon Managed Service for Apache Flink Application to stop¶
To wait on the state of an Amazon Managed Service for Apache Flink Application to stop you can use
KinesisAnalyticsV2StopApplicationCompletedSensor
.
tests/system/amazon/aws/example_kinesis_analytics.py
await_stop_application = KinesisAnalyticsV2StopApplicationCompletedSensor(
task_id="await_stop_application",
application_name=application_name,
)