Search code examples
amazon-s3azure-pipelinesaws-cli

Azure Devops - pipeline to delete single s3 file


I would like a pipeline setup that I can run manually. The idea here is that it deletes a single file held within an AWS S3 account. I know technically there are many ways to do this, but what is best practice?

Thank you!


Solution

  • You can use a task: AWS CLI and add it into pipeline to delete a single file held within an AWS S3 account. You can follow below steps :

    1、 You should create a service connection before adding a AWS CLI task to pipeline.

    Create AWS service connection

    2、 Add AWS CLI task to pipeline and configure required parameters. Please know the meaning of parameters about AWS CLI. You can refer the document :

    Command structure in the AWS CLI

    The command structure is like:

    aws <command> <subcommand> [options and parameters]
    

    In this example, you can use the command below to delete a single s3 file:

    aws s3 rm s3://BUCKET_NAME/uploads/file_name.jpg
    

    “s3://BUCKET_NAME/uploads/file_name.jpg” is the file path you saved in S3.

    AWS CLI in pipeline

    3 run the pipeline and the single s3 file can be deleted successfully.