Seleziona le tue preferenze relative ai cookie

Utilizziamo cookie essenziali e strumenti simili necessari per fornire il nostro sito e i nostri servizi. Utilizziamo i cookie prestazionali per raccogliere statistiche anonime in modo da poter capire come i clienti utilizzano il nostro sito e apportare miglioramenti. I cookie essenziali non possono essere disattivati, ma puoi fare clic su \"Personalizza\" o \"Rifiuta\" per rifiutare i cookie prestazionali.

Se sei d'accordo, AWS e le terze parti approvate utilizzeranno i cookie anche per fornire utili funzionalità del sito, ricordare le tue preferenze e visualizzare contenuti pertinenti, inclusa la pubblicità pertinente. Per continuare senza accettare questi cookie, fai clic su \"Continua\" o \"Rifiuta\". Per effettuare scelte più dettagliate o saperne di più, fai clic su \"Personalizza\".

Use PutBucketVersioning with an AWS SDK or CLI - Amazon Simple Storage Service
Questa pagina non è tradotta nella tua lingua. Richiedi traduzione

Use PutBucketVersioning with an AWS SDK or CLI

The following code examples show how to use PutBucketVersioning.

CLI
AWS CLI

The following command enables versioning on a bucket named amzn-s3-demo-bucket:

aws s3api put-bucket-versioning --bucket amzn-s3-demo-bucket --versioning-configuration Status=Enabled

The following command enables versioning, and uses an mfa code

aws s3api put-bucket-versioning --bucket amzn-s3-demo-bucket --versioning-configuration Status=Enabled --mfa "SERIAL 123456"
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Enables bucket versioning for the specified S3 bucket. * * @param s3Client the S3 client to use for the operation * @param bucketName the name of the S3 bucket to enable versioning for */ public static void enableBucketVersioning(S3Client s3Client, String bucketName){ VersioningConfiguration versioningConfiguration = VersioningConfiguration.builder() .status(BucketVersioningStatus.ENABLED) .build(); PutBucketVersioningRequest versioningRequest = PutBucketVersioningRequest.builder() .bucket(bucketName) .versioningConfiguration(versioningConfiguration) .build(); s3Client.putBucketVersioning(versioningRequest); System.out.println("Bucket versioning has been enabled for "+bucketName); }
PowerShell
Tools for PowerShell

Example 1: The command enables versioning for the given S3 bucket.

Write-S3BucketVersioning -BucketName 'amzn-s3-demo-bucket' -VersioningConfig_Status Enabled
AWS CLI

The following command enables versioning on a bucket named amzn-s3-demo-bucket:

aws s3api put-bucket-versioning --bucket amzn-s3-demo-bucket --versioning-configuration Status=Enabled

The following command enables versioning, and uses an mfa code

aws s3api put-bucket-versioning --bucket amzn-s3-demo-bucket --versioning-configuration Status=Enabled --mfa "SERIAL 123456"

For a complete list of AWS SDK developer guides and code examples, see Developing with Amazon S3 using the AWS SDKs. This topic also includes information about getting started and details about previous SDK versions.

Argomento successivo:

PutBucketWebsite

Argomento precedente:

PutBucketTagging
PrivacyCondizioni del sitoPreferenze cookie
© 2025, Amazon Web Services, Inc. o società affiliate. Tutti i diritti riservati.