Skip to content

Commit 943ff45

Browse files
committed
get msaf done
1 parent 2497c23 commit 943ff45

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

src/content/docs/aws/services/apacheflink.md

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
---
22
title: "Managed Service for Apache Flink"
3-
linkTitle: "Managed Service for Apache Flink"
43
description: >
54
Get started with Managed Service for Apache Flink on LocalStack
65
tags: ["Ultimate"]
76
---
87

9-
{{< callout >}}
8+
:::note
109
This service was formerly known as 'Kinesis Data Analytics for Apache Flink'.
11-
{{< /callout >}}
10+
:::
1211

1312
## Introduction
1413

1514
[Apache Flink](https://flink.apache.org/) is a framework for building applications that process and analyze streaming data.
1615
[Managed Service for Apache Flink (MSF)](https://docs.aws.amazon.com/managed-flink/latest/java/what-is.html) is an AWS service that provides the underlying infrastructure and a hosted Apache Flink cluster that can run Apache Flink applications.
1716

18-
LocalStack lets you to run Flink applications locally and implements several [AWS-compatible API operations]({{< ref "coverage_kinesisanalyticsv2" >}}).
17+
LocalStack lets you to run Flink applications locally and implements several [AWS-compatible API operations]().
1918

2019
A separate Apache Flink cluster is started in [application mode](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/deployment/overview/#application-mode) for every Managed Flink application created.
2120
Flink cluster deployment on LocalStack consists of two separate containers for [JobManager](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/concepts/flink-architecture/#jobmanager) and [TaskManager](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/concepts/flink-architecture/#taskmanagers).
2221

23-
{{< callout "note" >}}
22+
:::note
2423
The emulated MSF provider was introduced and made the default in LocalStack v4.1.
2524

2625
If you wish to use the older mock provider, you can set `PROVIDER_OVERRIDE_KINESISANALYTICSV2=legacy`.
27-
{{< /callout >}}
26+
:::
2827

2928
## Getting Started
3029

@@ -38,16 +37,16 @@ Start the LocalStack container using your preferred method.
3837
Begin by cloning the AWS sample repository.
3938
We will use the [S3 Sink](https://github.com/localstack-samples/amazon-managed-service-for-apache-flink-examples/tree/main/java/S3Sink) application in this example.
4039

41-
{{< command >}}
42-
$ git clone https://github.com/localstack-samples/amazon-managed-service-for-apache-flink-examples.git
43-
$ cd java/S3Sink
44-
{{< /command >}}
40+
```bash
41+
git clone https://github.com/localstack-samples/amazon-managed-service-for-apache-flink-examples.git
42+
cd java/S3Sink
43+
```
4544

4645
Next, use [Maven](https://maven.apache.org/) to compile and package the Flink application into a jar.
4746

48-
{{< command >}}
49-
$ mvn package
50-
{{< /command >}}
47+
```bash
48+
mvn package
49+
```
5150

5251
The Flink application jar file will be placed in the `./target/flink-kds-s3.jar` directory.
5352

@@ -57,20 +56,20 @@ MSF requires that all application code resides in S3.
5756

5857
Create an S3 bucket and upload the compiled Flink application jar.
5958

60-
{{< command >}}
61-
$ awslocal s3api create-bucket --bucket flink-bucket
62-
$ awslocal s3api put-object --bucket flink-bucket --key job.jar --body ./target/flink-kds-s3.jar
63-
{{< /command >}}
59+
```bash
60+
awslocal s3api create-bucket --bucket flink-bucket
61+
awslocal s3api put-object --bucket flink-bucket --key job.jar --body ./target/flink-kds-s3.jar
62+
```
6463

6564
### Output Sink
6665

6766
As mentioned earlier, this Flink application writes the output to an S3 bucket.
6867

6968
Create the S3 bucket that will serve as the sink.
7069

71-
{{< command >}}
72-
$ awslocal s3api create-bucket --bucket sink-bucket
73-
{{< /command >}}
70+
```bash
71+
awslocal s3api create-bucket --bucket sink-bucket
72+
```
7473

7574
### Permissions
7675

@@ -93,9 +92,9 @@ Create an IAM role for the running MSF application to assume.
9392
}
9493
```
9594

96-
{{< command >}}
97-
$ awslocal iam create-role --role-name msaf-role --assume-role-policy-document file://role.json
98-
{{< /command >}}
95+
```bash
96+
awslocal iam create-role --role-name msaf-role --assume-role-policy-document file://role.json
97+
```
9998

10099
Next create add a permissions policy to this role that permits read and write access to S3.
101100

@@ -113,18 +112,18 @@ Next create add a permissions policy to this role that permits read and write ac
113112
}
114113
```
115114

116-
{{< command >}}
117-
$ awslocal iam put-role-policy --role-name msaf-role --policy-name msaf-policy --policy-document file://policy.json
118-
{{< /command >}}
115+
```bash
116+
awslocal iam put-role-policy --role-name msaf-role --policy-name msaf-policy --policy-document file://policy.json
117+
```
119118

120119
Now, when the running MSF application assumes this role, it will have the necessary permissions to write to the S3 sink.
121120

122121
### Deploy Application
123122

124123
With all prerequisite resources in place, the Flink application can now be created and started.
125124

126-
{{< command >}}
127-
$ awslocal kinesisanalyticsv2 create-application \
125+
```bash
126+
awslocal kinesisanalyticsv2 create-application \
128127
--application-name msaf-app \
129128
--runtime-environment FLINK-1_20 \
130129
--application-mode STREAMING \
@@ -146,15 +145,15 @@ $ awslocal kinesisanalyticsv2 create-application \
146145
}
147146
}'
148147

149-
$ awslocal kinesisanalyticsv2 start-application --application-name msaf-app
150-
{{< /command >}}
148+
awslocal kinesisanalyticsv2 start-application --application-name msaf-app
149+
```
151150

152151
Once the Flink cluster is up and running, the application will stream the results to the sink S3 bucket.
153152
You can verify this with:
154153

155-
{{< command >}}
156-
$ awslocal s3api list-objects --bucket sink-bucket
157-
{{< /command >}}
154+
```bash
155+
awslocal s3api list-objects --bucket sink-bucket
156+
```
158157

159158
## CloudWatch Logging
160159

@@ -170,10 +169,15 @@ There are following prerequisites for CloudWatch Logs integration:
170169

171170
To add a logging option:
172171

173-
{{< command >}}
174-
$ awslocal kinesisanalyticsv2 add-application-cloud-watch-logging-option \
172+
```bash
173+
awslocal kinesisanalyticsv2 add-application-cloud-watch-logging-option \
175174
--application-name msaf-app \
176175
--cloud-watch-logging-option '{"LogStreamARN": "arn:aws:logs:us-east-1:000000000000:log-group:msaf-log-group:log-stream:msaf-log-stream"}'
176+
```
177+
178+
The response will be similar to:
179+
180+
```json
177181
{
178182
"ApplicationARN": "arn:aws:kinesisanalytics:us-east-1:000000000000:application/msaf-app",
179183
"ApplicationVersionId": 2,
@@ -184,34 +188,39 @@ $ awslocal kinesisanalyticsv2 add-application-cloud-watch-logging-option \
184188
}
185189
]
186190
}
187-
{{< /command >}}
191+
```
188192

189-
{{< callout >}}
193+
:::note
190194
Enabling CloudWatch Logs integration has a significant performance hit.
191-
{{< /callout >}}
195+
:::
192196

193197
Configured logging options can be retrieved using [DescribeApplication](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_DescribeApplication.html):
194198

195-
{{< command >}}
196-
$ awslocal kinesisanalyticsv2 describe-application --application-name msaf-app | jq .ApplicationDetail.CloudWatchLoggingOptionDescriptions
199+
```bash
200+
awslocal kinesisanalyticsv2 describe-application --application-name msaf-app | jq .ApplicationDetail.CloudWatchLoggingOptionDescriptions
201+
```
202+
203+
The response will be similar to:
204+
205+
```json
197206
[
198207
{
199208
"CloudWatchLoggingOptionId": "1.1",
200209
"LogStreamARN": "arn:aws:logs:us-east-1:000000000000:log-group:msaf-log-group:log-stream:msaf-log-stream"
201210
}
202211
]
203-
{{< /command >}}
212+
```
204213

205214
Log events can be retrieved from CloudWatch Logs using the appropriate operation.
206215
To retrieve all events:
207216

208-
{{< command >}}
209-
$ awslocal logs get-log-events --log-group-name msaf-log-group --log-stream-name msaf-log-stream
210-
{{< /command >}}
217+
```bash
218+
awslocal logs get-log-events --log-group-name msaf-log-group --log-stream-name msaf-log-stream
219+
```
211220

212-
{{< callout >}}
221+
:::note
213222
Logs events are reported to CloudWatch every 10 seconds.
214-
{{< /callout >}}
223+
:::
215224

216225
LocalStack reports both Flink application and Flink framework logs to CloudWatch.
217226
However, certain extended information such as stack traces may be missing.
@@ -222,13 +231,18 @@ You may obtain this information by execing into the Flink Docker container creat
222231
You can manage [resource tags](https://docs.aws.amazon.com/managed-flink/latest/java/how-tagging.html) using [TagResource](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_TagResource.html), [UntagResource](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_UntagResource.html) and [ListTagsForResource](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_ListTagsForResource.html).
223232
Tags can also be specified when creating the Flink application using the [CreateApplication](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_CreateApplication.html) operation.
224233

225-
{{< command >}}
226-
$ awslocal kinesisanalyticsv2 tag-resource \
234+
```bash
235+
awslocal kinesisanalyticsv2 tag-resource \
227236
--resource-arn arn:aws:kinesisanalytics:us-east-1:000000000000:application/msaf-app \
228237
--tags Key=country,Value=SE
229238

230-
$ awslocal kinesisanalyticsv2 list-tags-for-resource \
239+
awslocal kinesisanalyticsv2 list-tags-for-resource \
231240
--resource-arn arn:aws:kinesisanalytics:us-east-1:000000000000:application/msaf-app
241+
```
242+
243+
The response will be similar to:
244+
245+
```json
232246
{
233247
"Tags": [
234248
{
@@ -237,11 +251,15 @@ $ awslocal kinesisanalyticsv2 list-tags-for-resource \
237251
}
238252
]
239253
}
254+
```
255+
256+
You can also untag the resource:
240257

258+
```bash
241259
$ awslocal kinesisanalyticsv2 untag-resource \
242260
--resource-arn arn:aws:kinesisanalytics:us-east-1:000000000000:application/msaf-app \
243261
--tag-keys country
244-
{{< /command >}}
262+
```
245263

246264
## Supported Flink Versions
247265

0 commit comments

Comments
 (0)