

# Use the Managed Service for Apache Flink VPC API

Use the following Managed Service for Apache Flink API operations to manage VPCs for your application. For information on using the Managed Service for Apache Flink API, see [Managed Service for Apache Flink API example code](api-examples.md).

## Create application
<a name="vpc-api-create"></a>

Use the [CreateApplication](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_CreateApplication.html) action to add a VPC configuration to your application during creation.

The following example request code for the `CreateApplication` action includes a VPC configuration when the application is created:

```json
{
  "ApplicationName":"MyApplication",
  "ApplicationDescription":"My-Application-Description",
  "RuntimeEnvironment":"FLINK-1_15",
  "ServiceExecutionRole":"arn:aws:iam::123456789123:role/myrole",
  "ApplicationConfiguration": {
    "ApplicationCodeConfiguration":{
      "CodeContent":{
        "S3ContentLocation":{
          "BucketARN":"arn:aws:s3:::amzn-s3-demo-bucket",
          "FileKey":"myflink.jar",
          "ObjectVersion":"AbCdEfGhIjKlMnOpQrStUvWxYz12345"
        }
      },
      "CodeContentType":"ZIPFILE"
    },
      "FlinkApplicationConfiguration":{
      "ParallelismConfiguration":{
        "ConfigurationType":"CUSTOM",
        "Parallelism":2,
        "ParallelismPerKPU":1,
        "AutoScalingEnabled":true
      }
    },
  {{"VpcConfigurations": [ 
         { 
            "SecurityGroupIds": [ "sg-0123456789abcdef0" ],
            "SubnetIds": [ "subnet-0123456789abcdef0" ]
         }
      ]}}
  }
}
```

## AddApplicationVpcConfiguration
<a name="vpc-api-add"></a>

Use the [AddApplicationVpcConfiguration](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_AddApplicationVpcConfiguration.html) action to add a VPC configuration to your application after it has been created.

The following example request code for the `AddApplicationVpcConfiguration` action adds a VPC configuration to an existing application:

```json
{
   "ApplicationName": "MyApplication",
   "CurrentApplicationVersionId": 9,
   "VpcConfiguration": { 
      "SecurityGroupIds": [ "sg-0123456789abcdef0" ],
      "SubnetIds": [ "subnet-0123456789abcdef0" ]
   }
}
```

**Note**  
If the application is `RUNNING` in enhanced snapshot mode and `SnapshotsEnabled` is `true`, Managed Service for Apache Flink creates a system snapshot. The caller of `AddApplicationVpcConfiguration` needs `kinesisanalytics:CreateSystemSnapshot` on the application ARN. For more information, see [System snapshots](snapshots-how-it-works.md#snapshots-how-it-works-system-snapshots).

## DeleteApplicationVpcConfiguration
<a name="vpc-api-del"></a>

Use the [DeleteApplicationVpcConfiguration](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_DeleteApplicationVpcConfiguration.html) action to remove a VPC configuration from your application.

The following example request code for the `AddApplicationVpcConfiguration` action removes an existing VPC configuration from an application:

```json
{
   "ApplicationName": "MyApplication",
   "CurrentApplicationVersionId": 9,
   "VpcConfigurationId": "1.1"
}
```

**Note**  
If the application is `RUNNING` in enhanced snapshot mode and `SnapshotsEnabled` is `true`, Managed Service for Apache Flink creates a system snapshot. The caller of `DeleteApplicationVpcConfiguration` needs `kinesisanalytics:CreateSystemSnapshot` on the application ARN. For more information, see [System snapshots](snapshots-how-it-works.md#snapshots-how-it-works-system-snapshots).

## Update application
<a name="vpc-api-upd"></a>

Use the [UpdateApplication](https://docs.aws.amazon.com/managed-flink/latest/apiv2/API_UpdateApplication.html) action to update all of an application's VPC configurations at once.

The following example request code for the `UpdateApplication` action updates all of the VPC configurations for an application:

```json
{
   "ApplicationConfigurationUpdate": { 
      "VpcConfigurationUpdates": [ 
         { 
            "SecurityGroupIdUpdates": [ "sg-0123456789abcdef0" ],
            "SubnetIdUpdates": [ "subnet-0123456789abcdef0" ],
            "VpcConfigurationId": "2.1"
         }
      ]
   },
   "ApplicationName": "MyApplication",
   "CurrentApplicationVersionId": 9
}
```