Back to Aws Doc Sdk Examples

Amazon S3 Object Lock Workflow for the SDK for Python (boto3)

python/example_code/s3/scenarios/object-locking/README.md

latest2.7 KB
Original Source

Amazon S3 Object Lock Workflow for the SDK for Python (boto3)

Overview

This example demonstrates how to use the AWS SDK for Python (boto3) to work with Amazon Simple Storage Service (Amazon S3) object locking features. The workflow shows how to create, update, view, and modify object locks, as well as how locked objects behave regarding requests to delete and overwrite.

Amazon S3 Object Lock can help prevent Amazon S3 objects from being deleted or overwritten for a fixed amount of time or indefinitely. Object Lock can help meet regulatory requirements or protect against object changes or deletion.

⚠ Important

  • Running this code might result in charges to your AWS account. For more details, see AWS Pricing and Free Tier.
  • Running the tests might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.

Code examples

Prerequisites

To run these examples, you need:

  • Python 3.x installed.
  • Run python pip install -r requirements.txt
  • AWS credentials configured. For more information, see Configuring the AWS CLI.

Scenarios

This example uses a workflow approach to demonstrate various aspects of S3 Object Locking. The workflow is divided into three stages:

  1. Deploy: Create buckets with different object locking configurations, populate buckets with objects, and set object lock and retention policies.
  2. Demo: Explore S3 locking features by listing objects, attempting to delete or overwrite locked objects, and viewing retention and legal hold settings.
  3. Clean: Remove object locks and retention periods, delete all objects and buckets.

Running the workflow

To run this workflow, pull AWS tokens and run the command below:

bash
python main.py

Additional resources


© Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0