Obtenha a configuração de retenção legal de um objeto do Amazon S3 usando um SDK AWS - AWS Exemplos de código do SDK

Há mais exemplos de AWS SDK disponíveis no repositório AWS Doc SDK Examples GitHub .

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Obtenha a configuração de retenção legal de um objeto do Amazon S3 usando um SDK AWS

O exemplo de código a seguir mostra como obter a configuração de retenção jurídica de um bucket do S3.

.NET
AWS SDK for .NET
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

/// <summary> /// Get the legal hold details for an S3 object. /// </summary> /// <param name="bucketName">The bucket of the object.</param> /// <param name="objectKey">The object key.</param> /// <returns>The object legal hold details.</returns> public async Task<ObjectLockLegalHold> GetObjectLegalHold(string bucketName, string objectKey) { try { var request = new GetObjectLegalHoldRequest() { BucketName = bucketName, Key = objectKey }; var response = await _amazonS3.GetObjectLegalHoldAsync(request); Console.WriteLine($"\tObject legal hold for {objectKey} in {bucketName}: " + $"\n\tStatus: {response.LegalHold.Status}"); return response.LegalHold; } catch (AmazonS3Exception ex) { Console.WriteLine($"\tUnable to fetch legal hold: '{ex.Message}'"); return new ObjectLockLegalHold(); } }
  • Para obter detalhes da API, consulte GetObjectLegalHolda Referência AWS SDK for .NET da API.

Java
SDK para Java 2.x
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

// Get the legal hold details for an S3 object. public ObjectLockLegalHold getObjectLegalHold(String bucketName, String objectKey) { try { GetObjectLegalHoldRequest legalHoldRequest = GetObjectLegalHoldRequest.builder() .bucket(bucketName) .key(objectKey) .build(); GetObjectLegalHoldResponse response = getClient().getObjectLegalHold(legalHoldRequest); System.out.println("Object legal hold for " + objectKey + " in " + bucketName + ":\n\tStatus: " + response.legalHold().status()); return response.legalHold(); } catch (S3Exception ex) { System.out.println("\tUnable to fetch legal hold: '" + ex.getMessage() + "'"); } return null; }
  • Para obter detalhes da API, consulte GetObjectLegalHolda Referência AWS SDK for Java 2.x da API.

JavaScript
SDK para JavaScript (v3)
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { fileURLToPath } from "url"; import { GetObjectLegalHoldCommand, S3Client } from "@aws-sdk/client-s3"; /** * @param {S3Client} client * @param {string} bucketName * @param {string} objectKey */ export const main = async (client, bucketName, objectKey) => { const command = new GetObjectLegalHoldCommand({ Bucket: bucketName, Key: objectKey, // Optionally, you can provide additional parameters // ExpectedBucketOwner: "ACCOUNT_ID", // RequestPayer: "requester", // VersionId: "OBJECT_VERSION_ID", }); try { const response = await client.send(command); console.log(`Legal Hold Status: ${response.LegalHold.Status}`); } catch (err) { console.error(err); } }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { main(new S3Client(), "DOC-EXAMPLE-BUCKET", "OBJECT_KEY"); }
  • Para obter detalhes da API, consulte GetObjectLegalHolda Referência AWS SDK for JavaScript da API.