Skip to content

Commit

Permalink
.NET v3: Add the S3 Object Lock Workflow Scenario (awsdocs#6179)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlhagerm committed Feb 29, 2024
1 parent 184c16e commit 4d5fd36
Show file tree
Hide file tree
Showing 15 changed files with 1,817 additions and 0 deletions.
142 changes: 142 additions & 0 deletions .doc_gen/metadata/s3_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ s3_CreateBucket:
- description:
snippet_tags:
- S3.dotnetv3.S3_Basics-CreateBucket
- description: Create a bucket with object lock enabled.
snippet_tags:
- S3LockWorkflow.dotnetv3.CreateBucketWithObjectLock
C++:
versions:
- sdk_version: 1
Expand Down Expand Up @@ -954,6 +957,57 @@ s3_GetBucketLifecycleConfiguration:
- python.example_code.s3.GetBucketLifecycleConfiguration
services:
s3: {GetBucketLifecycleConfiguration}
s3_GetObjectLegalHoldConfiguration:
title: Get the legal hold configuration of an &S3; object using an &AWS; SDK
title_abbrev: Get the legal hold configuration of an object
synopsis: get the legal hold configuration of an S3 bucket.
category:
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description:
snippet_tags:
- S3LockWorkflow.dotnetv3.GetObjectLegalHold
services:
s3: {GetObjectLegalHold}
s3_GetObjectLockConfiguration:
title: Get the object lock configuration of an &S3; bucket using an &AWS; SDK
title_abbrev: Get the object lock configuration of a bucket
synopsis: get the object lock configuration of an S3 bucket.
category:
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description:
snippet_tags:
- S3LockWorkflow.dotnetv3.GetBucketObjectLockConfiguration
services:
s3: {GetObjectLockConfiguration}
s3_GetObjectRetention:
title: Get the retention configuration of an &S3; object using an &AWS; SDK
title_abbrev: Get the retention configuration of an object
synopsis: get the retention configuration of an S3 object.
category:
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description:
snippet_tags:
- S3LockWorkflow.dotnetv3.GetObjectRetention
services:
s3: {GetObjectRetention}
s3_ServiceAccessLogging:
title: Enable logging on an &S3; bucket using an &AWS; SDK
title_abbrev: Enable logging
Expand Down Expand Up @@ -2088,6 +2142,74 @@ s3_PutObjectAcl:
- s3.cpp.put_object_acl.code
services:
s3: {PutObjectAcl}
s3_PutObjectLegalHold:
title: Set the legal hold configuration of an &S3; object using an &AWS; SDK
title_abbrev: Set the legal hold configuration of an object
synopsis: set the legal hold configuration of an S3 object.
category:
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description:
snippet_tags:
- S3LockWorkflow.dotnetv3.ModifyObjectLegalHold
services:
s3: {PutObjectLegalHold}
s3_PutObjectLockConfiguration:
title: Set the object lock configuration of an &S3; bucket using an &AWS; SDK
title_abbrev: Set the object lock configuration of an bucket
synopsis: set the object lock configuration of an existing S3 bucket.
category:
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description:
snippet_tags:
- S3LockWorkflow.dotnetv3.EnableObjectLockOnBucket
services:
s3: {PutObjectLockConfiguration}
s3_PutObjectRetention:
title: Set the retention period of an &S3; object using an &AWS; SDK
title_abbrev: Set the retention period of an object
synopsis: set the retention period of an S3 object.
category:
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description:
snippet_tags:
- S3LockWorkflow.dotnetv3.ModifyObjectRetentionPeriod
services:
s3: {PutObjectRetention}
s3_PutDefaultObjectLockConfiguration:
title: Set the default retention period of an &S3; bucket using an &AWS; SDK
title_abbrev: Set the default retention period of a bucket
synopsis: set the default retention period of an S3 bucket.
category:
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description:
snippet_tags:
- S3LockWorkflow.dotnetv3.ModifyBucketDefaultRetention
services:
s3: {PutObjectLockConfiguration}
s3_UploadPart:
title: Upload a single part of a multipart upload using an &AWS; SDK
title_abbrev: Upload a single part of a multipart upload
Expand Down Expand Up @@ -2931,3 +3053,23 @@ s3_GetObject_MRAP:
- s3.kotlin.mrap.getobject
services:
s3: {GetObject}
s3_Scenario_ObjectLock:
title: Work with &S3; object lock features using an &AWS; SDK
title_abbrev: Lock &S3; objects
synopsis: work with S3 object lock features.
category: Scenarios
languages:
.NET:
versions:
- sdk_version: 3
github: dotnetv3/S3/scenarios/S3ObjectLockScenario
sdkguide:
excerpts:
- description: Run an interactive scenario demonstrating &S3; object lock features.
snippet_tags:
- S3LockWorkflow.dotnetv3.ObjectLockWorkflow
- description: A wrapper class for S3 functions.
snippet_tags:
- S3LockWorkflow.dotnetv3.S3ActionsWrapper
services:
s3: {PutObjectLockConfiguration, PutObjectRetention, GetObjectRetention, PutObjectLegalHold, GetObjectLegalHold, GetObjectLockConfiguration}
20 changes: 20 additions & 0 deletions dotnetv3/S3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ Code excerpts that show you how to call individual service functions.
- [Get CORS rules for a bucket](s3CORSExample/S3CORS.cs#L125) (`GetBucketCors`)
- [Get an object from a bucket](S3_Basics/S3Bucket.cs#L85) (`GetObject`)
- [Get the ACL of a bucket](BucketACLExample/BucketACL.cs#L75) (`GetBucketAcl`)
- [Get the legal hold configuration of an object](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ActionsWrapper.cs#L259) (`GetObjectLegalHold`)
- [Get the lifecycle configuration of a bucket](LifecycleExample/Lifecycle.cs#L169) (`GetBucketLifecycleConfiguration`)
- [Get the object lock configuration of a bucket](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ActionsWrapper.cs#L290) (`GetObjectLockConfiguration`)
- [Get the retention configuration of an object](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ActionsWrapper.cs#L193) (`GetObjectRetention`)
- [Get the website configuration for a bucket](WebsiteConfigExample/WebsiteConfig.cs#L72) (`GetBucketWebsite`)
- [List buckets](ListBucketsExample/ListBuckets.cs#L4) (`ListBuckets`)
- [List object versions in a bucket](versioned-examples/ListObjectVersionsExample/ListObjectVersions.cs#L6) (`ListObjectVersions`)
- [List objects in a bucket](S3_Basics/S3Bucket.cs#L171) (`ListObjectsV2`)
- [Restore an archived copy of an object](RestoreArchivedObjectExample/RestoreArchivedObject.cs#L6) (`RestoreObject`)
- [Set a new ACL for a bucket](BucketACLExample/BucketACL.cs#L37) (`PutBucketAcl`)
- [Set the default retention period of a bucket](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ActionsWrapper.cs#L139) (`PutObjectLockConfiguration`)
- [Set the legal hold configuration of an object](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ActionsWrapper.cs#L224) (`PutObjectLegalHold`)
- [Set the object lock configuration of an bucket](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ActionsWrapper.cs#L60) (`PutObjectLockConfiguration`)
- [Set the retention period of an object](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ActionsWrapper.cs#L102) (`PutObjectRetention`)
- [Set the website configuration for a bucket](WebsiteConfigExample/WebsiteConfig.cs#L57) (`PutBucketWebsite`)
- [Upload an object to a bucket](S3_Basics/S3Bucket.cs#L43) (`PutObject`)

Expand All @@ -68,6 +75,7 @@ functions within the same service.
- [Get started with buckets and objects](S3_Basics/S3_Basics.cs)
- [Get started with encryption](SSEClientEncryptionExample/SSEClientEncryption.cs)
- [Get started with tags](ObjectTagExample/ObjectTag.cs)
- [Lock Amazon S3 objects](scenarios/S3ObjectLockScenario/S3ObjectLockWorkflow/S3ObjectLockWorkflow.cs)
- [Manage access control lists (ACLs)](ManageACLsExample/ManageACLs.cs)
- [Perform a multipart copy](MPUapiCopyObjExample/MPUapiCopyObj.cs)
- [Upload or download large files](scenarios/TransferUtilityBasics/TransferUtilityBasics/TransferBasics.cs)
Expand Down Expand Up @@ -163,6 +171,18 @@ This example shows you how to get started with tags for Amazon S3 objects.
<!--custom.scenarios.s3_Scenario_Tagging.start-->
<!--custom.scenarios.s3_Scenario_Tagging.end-->

#### Lock Amazon S3 objects

This example shows you how to work with S3 object lock features.


<!--custom.scenario_prereqs.s3_Scenario_ObjectLock.start-->
<!--custom.scenario_prereqs.s3_Scenario_ObjectLock.end-->


<!--custom.scenarios.s3_Scenario_ObjectLock.start-->
<!--custom.scenarios.s3_Scenario_ObjectLock.end-->

#### Manage access control lists (ACLs)

This example shows you how to manage access control lists (ACLs) for Amazon S3 buckets.
Expand Down
57 changes: 57 additions & 0 deletions dotnetv3/S3/scenarios/S3ObjectLockScenario/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Amazon S3 Object Lock Workflow

## Overview

This example shows how to use AWS SDKs to work with Amazon Simple Storage Service (Amazon S3) object locking features. The workflow demonstrates 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](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html) 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.

![Object Lock Features](../../../../workflows/s3_object_lock/resources/Diagram_Amazon-S3-Object-Lock.png)

This workflow demonstrates the following steps and tasks:
1. Add object lock settings to both new and existing S3 buckets.
1. Add objects to buckets with optional object lock or retention period settings.
2. Attempt to delete or overwrite locked objects.
3. Retrieve and view the object lock and retention period settings of buckets and objects.
4. Delete the objects and buckets.
1. Remove any object locks and use the BypassGovernanceRetention setting.

## ⚠ Important

* Running this code might result in charges to your AWS account.
* 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](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).

## Scenario

### Prerequisites

For general prerequisites, see the [README](../../../README.md) in the `dotnetv3` folder.

### Resources

The workflow scenario steps create the buckets and objects needed for the example. No additional resources are required.

This workflow includes an optional step to add a governance mode retention period of one day to objects in an S3 bucket. In order to delete these objects, you must have the `s3:BypassGovernanceRetention` permission. If you do not have this permission, you will be unable to delete these objects until the retention period has expired.

### Instructions

After the example compiles, you can run it from the command line. To do so, navigate to
the folder that contains the .sln file and run the following command:

```
dotnet run
```

Alternatively, you can run the example from within your IDE.

This starts an interactive scenario that walks you through creating, exploring, and deleting S3 buckets and objects with various object lock settings.

## Additional resources

- [S3 Object Lock](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html)

---

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "S3ObjectLockScenario", "S3ObjectLockWorkflow\S3ObjectLockScenario.csproj", "{AD5B04A6-0ED1-4384-9125-2E64B7898B52}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "S3ObjectLockTests", "S3ObjectLockTests\S3ObjectLockTests.csproj", "{9E2CFE55-8998-44D2-8331-93AAE8554677}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AD5B04A6-0ED1-4384-9125-2E64B7898B52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD5B04A6-0ED1-4384-9125-2E64B7898B52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD5B04A6-0ED1-4384-9125-2E64B7898B52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD5B04A6-0ED1-4384-9125-2E64B7898B52}.Release|Any CPU.Build.0 = Release|Any CPU
{9E2CFE55-8998-44D2-8331-93AAE8554677}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E2CFE55-8998-44D2-8331-93AAE8554677}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E2CFE55-8998-44D2-8331-93AAE8554677}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E2CFE55-8998-44D2-8331-93AAE8554677}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E2318334-46A6-4814-892D-EE6AE0307BEC}
EndGlobalSection
EndGlobal
Loading

0 comments on commit 4d5fd36

Please sign in to comment.