Set up enhanced snapshots
This page describes how to create a new Amazon Managed Service for Apache Flink application in enhanced snapshot mode. It covers the prerequisites, the AWS Identity and Access Management (IAM) permissions, and the steps to create your first enhanced snapshot.
Prerequisites
Before you create an application in enhanced snapshot mode, check the following requirements.
- Apache Flink version
The application must use Apache Flink version 1.20 or later.
- Region
Enhanced snapshots are available in the AWS Regions where Managed Service for Apache Flink operates, except the AWS Top Secret Cloud Regions and the AWS European Sovereign Cloud. Enhanced snapshots aren't available in the AWS Top Secret Cloud Regions or the AWS European Sovereign Cloud at this time. If a request returns
UnsupportedOperationException, enhanced snapshots aren't available for your account in the Region of the request.
The Apache Flink version range includes every RuntimeEnvironment value from FLINK-1_20 on.
For Apache Flink 1.19 or earlier, a CreateApplication or UpdateApplication request that sets SnapshotMode to ENHANCED_SNAPSHOTS returns InvalidArgumentException.
For an application on Apache Flink 1.19 or earlier, CreateSnapshot returns InvalidApplicationConfigurationException.
New applications do not use enhanced snapshot mode by default.
To use enhanced snapshot mode, set SnapshotMode to ENHANCED_SNAPSHOTS in your
CreateApplication request.
To upgrade an existing application to enhanced snapshot mode, see Upgrade an existing application to enhanced snapshots.
IAM permissions
Enhanced snapshots add new AWS Identity and Access Management (IAM) actions. Managed Service for Apache Flink checks these actions on the principal that calls each enhanced snapshot API.
- Caller permissions
-
The caller needs the enhanced snapshot action for each API that it calls. Examples are
kinesisanalytics:CreateSnapshotandkinesisanalytics:DescribeSnapshot. RestoreFromSnapshot-
A restore in enhanced snapshot mode needs
kinesisanalytics:RestoreFromSnapshoton the enhanced snapshot that the restore uses.Managed Service for Apache Flink denies the restore by default, even for a snapshot that your own application created.
Managed Service for Apache Flink checks this action in the following cases:
StartApplication, in any application status.UpdateApplication, for aRUNNINGapplication only.AddApplicationVpcConfigurationandDeleteApplicationVpcConfiguration, for aRUNNINGapplication only.AddApplicationCloudWatchLoggingOptionandDeleteApplicationCloudWatchLoggingOption, for aRUNNINGapplication only.RollbackApplication, for aRUNNING,UPDATING, orAUTOSCALINGapplication. For the snapshot that a rollback uses, see Roll back an application.
Managed Service for Apache Flink does not check this action when
ApplicationRestoreTypeisSKIP_RESTORE_FROM_SNAPSHOT. ForRESTORE_FROM_LATEST_SNAPSHOTwithSnapshotsEnabledset totrue, Managed Service for Apache Flink also skips the check. This second rule applies to the following APIs:UpdateApplicationAddApplicationVpcConfigurationandDeleteApplicationVpcConfigurationAddApplicationCloudWatchLoggingOptionandDeleteApplicationCloudWatchLoggingOption
With
SnapshotsEnabledset tofalse, these APIs also check an enhanced snapshot of the application in theCREATINGstatus. For more information, see Restore from the latest snapshot. CreateSystemSnapshot-
For an application in enhanced snapshot mode with
SnapshotsEnabledset totrue, the following APIs needkinesisanalytics:CreateSystemSnapshoton the application ARN:StartApplication, in any application status.StopApplication, for aRUNNINGapplication. AStopApplicationrequest withForceset totruedoes not need the action.UpdateApplication, for aRUNNINGapplication. The request needs the action if it sets or keeps enhanced snapshot mode. The request also needs the action ifSnapshotsEnabledistrueafter the update.AddApplicationVpcConfiguration, for aRUNNINGapplication.DeleteApplicationVpcConfiguration, for aRUNNINGapplication.AddApplicationCloudWatchLoggingOption, for aRUNNINGapplication.DeleteApplicationCloudWatchLoggingOption, for aRUNNINGapplication.
CreateApplicationandRollbackApplicationdo not check this action. For more information about system snapshots, see System snapshots. - Service execution role
-
Enhanced snapshots need no changes to the service execution role.
- Customer managed keys and AWS KMS
-
Keep your existing key policy for an application that uses a customer managed key. That key policy already grants access to the service principals
kinesisanalytics.amazonaws.comandinfrastructure.kinesisanalytics.amazonaws.com. The caller ofCreateSnapshotalso needskms:Decryptandkms:GenerateDataKeyon the key.If the caller lacks one of these two AWS KMS permissions on the customer managed key,
CreateSnapshotreturnsAccessDeniedException. Managed Service for Apache Flink does not run this check for an AWS owned key.
For example caller policies, see Identity-based policy examples for enhanced snapshots. When you write a caller policy, apply the following rules:
To restore from system snapshots, allow
kinesisanalytics:RestoreFromSnapshotonsnapshot/SYSTEMSNAPSHOT-*. This pattern matches the system snapshots of every application in the account.Use
"*"as the resource forkinesisanalytics:ListSnapshots, even if you callListSnapshotswithSourceApplicationName.Add a AWS KMS statement only if the application uses a customer managed key.
For the full list of actions, resources, and condition keys, see How Amazon Managed Service for Apache Flink works with IAM. For more policy examples, see Identity-based policy examples for Amazon Managed Service for Apache Flink.
Create an application in enhanced snapshot mode
To create an application in enhanced snapshot mode, set SnapshotMode to ENHANCED_SNAPSHOTS in the CreateApplication request.
The member is ApplicationConfiguration.ApplicationSnapshotConfiguration.SnapshotMode.
-
SnapshotsEnabledstays mandatory inApplicationSnapshotConfiguration. -
If you omit
SnapshotMode, the application usesAPPLICATION_SNAPSHOTS_LEGACY. -
If you set
SnapshotModetoENHANCED_SNAPSHOTSon Apache Flink 1.19 or earlier,CreateApplicationreturnsInvalidArgumentException.CreateApplicationalso returnsInvalidArgumentExceptionif you setENHANCED_SNAPSHOTSfor a runtime other than Apache Flink, such asSQL-1_0. -
CreateApplicationtakes no snapshot.
To create an application in enhanced snapshot mode
-
Open a terminal where the AWS Command Line Interface (AWS CLI) is installed and configured.
-
Save the following JSON request as
create-application.json.{ "ApplicationName": "MyApplication", "RuntimeEnvironment": "FLINK-1_20", "ServiceExecutionRole": "arn:aws:iam::111122223333:role/MyApplicationServiceRole", "ApplicationConfiguration": { "ApplicationCodeConfiguration": { "CodeContent": { "S3ContentLocation": { "BucketARN": "arn:aws:s3:::amzn-s3-demo-bucket", "FileKey": "my-flink-app.jar" } }, "CodeContentType": "ZIPFILE" }, "ApplicationSnapshotConfiguration": { "SnapshotsEnabled": true, "SnapshotMode": "ENHANCED_SNAPSHOTS" } } } -
Replace the role ARN, bucket ARN, and file key in
create-application.jsonwith your own values. -
Run the following AWS CLI command in the terminal to send the request.
PROMPT> aws kinesisanalyticsv2 create-application --cli-input-json file://create-application.json -
Run the following AWS CLI command in the terminal to describe the application.
PROMPT> aws kinesisanalyticsv2 describe-application --application-name MyApplication -
Confirm that
ApplicationDetail.ApplicationConfigurationDescription.ApplicationSnapshotConfigurationDescription.SnapshotModeisENHANCED_SNAPSHOTSin theDescribeApplicationresponse.{ "ApplicationSnapshotConfigurationDescription": { "SnapshotsEnabled": true, "SnapshotMode": "ENHANCED_SNAPSHOTS" } }
Create your first enhanced snapshot
After the application reaches the RUNNING status, create an enhanced snapshot with
CreateSnapshot.
Managed Service for Apache Flink creates the enhanced snapshot asynchronously.
To create your first enhanced snapshot
-
Run the following AWS CLI command in the terminal to start the application with
StartApplication.PROMPT> aws kinesisanalyticsv2 start-application --application-name MyApplication -
Run the AWS CLI
describe-applicationcommand in the terminal untilApplicationStatusisRUNNING. -
Send a JSON
CreateSnapshotrequest with the application name and a snapshot name. The snapshot name must be unique in the account and Region.{ "ApplicationName": "MyApplication", "SnapshotName": "MyApplication-snapshot-1" }Run the following AWS CLI command to send the same request:
PROMPT> aws kinesisanalyticsv2 create-snapshot \ --application-name MyApplication \ --snapshot-name MyApplication-snapshot-1Replace
MyApplicationwith the name of your application. ReplaceMyApplication-snapshot-1with a name for the enhanced snapshot.If the request fails, check the exception.
AccessDeniedExceptionmeans that the caller lackskinesisanalytics:CreateSnapshotor a required AWS KMS permission.InvalidArgumentExceptionmeans that the snapshot name breaks the name rules. For all errors, see Troubleshoot snapshot API errors.Creating the enhanced snapshot can take several minutes. In the response,
SnapshotStatusisCREATING. Note theSnapshotOperationIdvalue. You use it if the enhanced snapshot fails. For the full response, see Create an enhanced snapshot.
To verify your first enhanced snapshot
-
Call
DescribeSnapshotin the terminal with the snapshot name. Repeat the call untilSnapshotStatusisREADYorFAILED. This process might take several minutes.PROMPT> aws kinesisanalyticsv2 describe-snapshot --snapshot-name MyApplication-snapshot-1The status is in
SnapshotInfoDetails.SnapshotStatus. For the full response, see Describe an enhanced snapshot. -
Call
DescribeSnapshotOperationifSnapshotStatusisFAILED. Use theSnapshotOperationIdfrom theCreateSnapshotresponse. The following example shell script checks the status and prints the failure details:PROMPT> STATUS=$(aws kinesisanalyticsv2 describe-snapshot \ --snapshot-name MyApplication-snapshot-1 \ --query 'SnapshotInfoDetails.SnapshotStatus' \ --output text) PROMPT> if [ "$STATUS" = "FAILED" ]; then aws kinesisanalyticsv2 describe-snapshot-operation --snapshot-name MyApplication-snapshot-1 \ --snapshot-operation-id a1B2c3D4e5F6 \ --query 'SnapshotOperationInfoDetails.SnapshotOperationFailureDetails' fiIn this example, replace
a1B2c3D4e5F6with yourSnapshotOperationIdvalue. For more information about snapshot operations, see Monitor enhanced snapshot operations.
For the errors that CreateSnapshot returns, see Troubleshoot snapshot API errors.
The legacy CreateApplicationSnapshot API returns InvalidApplicationConfigurationException for an application in enhanced snapshot mode.
Wait until the enhanced snapshot status is READY before you call UpdateApplication.