Pause a data pipeline (Python SDK V2)

Updated at:

Calls PauseDataPipeline through OSS Python SDK V2 to pause a specified data pipeline (DataPipeline) rule.

Prerequisites

  • OSS Python SDK V2 is installed. You can run pip install alibabacloud-oss-v2 to install it.

  • Access credentials are configured by using environment variables. The example in this topic uses EnvironmentVariableCredentialsProvider to read credentials from the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.

  • DataPipeline operations are forwarded by OSS to the underlying workflow service. Make sure that the source general-purpose bucket and the destination vector bucket are located in the same region.

Sample code

import argparse

import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.dataprocess as oss_dataprocess

parser = argparse.ArgumentParser(description="pause data pipeline sample")
parser.add_argument('--region', help='The region of the bucket.', required=True)
parser.add_argument('--endpoint', help='The endpoint of OSS.')
parser.add_argument('--data-pipeline-name', help='The name of the data pipeline.', required=True)


def main():
    args = parser.parse_args()

    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint
    client = oss_dataprocess.Client(cfg)

    try:
        result = client.pause_data_pipeline(
            oss_dataprocess.models.PauseDataPipelineRequest(
                data_pipeline_name=args.data_pipeline_name,
            ))
        print(f'status code: {result.status_code}, request id: {result.request_id}')
    except Exception as e:
        print(f'error:\n{e}')


if __name__ == '__main__':
    main()