حذف پیکربندی چرخه حیات از صندوقچه
مولفهها
- کلیدهای احراز هویت
- نام صندوقچه
- NET.
- PHP
- Python
- Javascript
- GO
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache - 2.0
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Threading.Tasks;
using System.Reflection;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace DeleteBucketLifecycleConfiguration
{
class DeleteBucketLifecycleConfiguration
{
private static IAmazonS3 _s3Client;
private const string BUCKET_NAME = "<BUCKET_NAME>";
static void Main()
{
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("<ACCESS_KEY>", "<SECRET_KEY>");
var config = new AmazonS3Config { ServiceURL = "<ENDPOINT_URL>" };
_s3Client = new AmazonS3Client(awsCredentials, config);
DeleteBucketLifecycle().Wait();
}
private static async Task DeleteBucketLifecycle()
{
try
{
// Create the request
DeleteLifecycleConfigurationRequest request = new()
{
BucketName = BUCKET_NAME,
};
// Submit the request
DeleteLifecycleConfigurationResponse response = await _s3Client.DeleteLifecycleConfigurationAsync(request);
Console.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Console.WriteLine($"Lifecycle configuration successfully deleted from {BUCKET_NAME} bucket");
}
catch (AmazonS3Exception amazonS3Exception)
{
Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
}
}
<?php
require('client.php');
$bucket = '<BUCKET_NAME>';
try {
$result = $client->deleteBucketLifecycle([
'Bucket' => $bucket, // REQUIRED
]);
var_dump($result);
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}
import boto3
import logging
from botocore.exceptions import ClientError
logging.basicConfig(level=logging.INFO)
try:
s3_client = boto3.client(
's3',
endpoint_url='<ENDPOINT_URL>',
aws_access_key_id='<ACCESS_KEY>',
aws_secret_access_key='<SECRET_KEY>'
)
except Exception as exc:
logging.error(exc)
else:
try:
response = s3_client.delete_bucket_lifecycle(
Bucket='<BUCKET_NAME>',
# ExpectedBucketOwner='string'
)
logging.info(response)
except ClientError as exc:
logging.error(exc)
// Import required AWS SDK clients and commands for Node.js
const {
S3Client,
DeleteBucketLifecycleCommand,
} = require('@aws-sdk/client-s3');
// Create an S3 client service object
const s3 = new S3Client({
region: 'default',
endpoint: '<ENDPOINT_URL>',
credentials: {
accessKeyId: '<ACCESS_KEY>',
secretAccessKey: '<SECRET_KEY>',
},
});
const BUCKET_NAME = '<BUCKET_NAME>';
const run = async () => {
try {
const response = await s3.send(
new DeleteBucketLifecycleCommand({
Bucket: BUCKET_NAME,
})
);
console.log('Success', response);
} catch (err) {
console.log('Error', err);
}
};
run();
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
// Deletes bucket lifecycle configuration.
//
// Usage:
// go run s3_delete_bucket_lifecycle_configuration BUCKET_NAME
func main() {
if len(os.Args) != 2 {
exitErrorf("Bucket name required\nUsage: %s bucket_name",
os.Args[0])
}
bucket := os.Args[1]
// Initialize a session in us-west-2 that the SDK will use to load
// credentials from the shared credentials file ~/.aws/credentials.
sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials("<ACCESS_KEY>", "<SECRET_KEY>", ""),
})
svc := s3.New(sess, &aws.Config{
Region: aws.String("default"),
Endpoint: aws.String("<ENDPOINT_URL>"),
})
// Deletes bucket lifecycle configuration
_, err = svc.DeleteBucketLifecycle(&s3.DeleteBucketLifecycleInput{Bucket: aws.String(bucket)})
if err != nil {
exitErrorf("Unable to delete bucket lifecycle configuration from bucket %q, %v", bucket, err)
}
fmt.Printf("Bucket lifecycle configuration successfully deleted\n")
}
func exitErrorf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1)
}
برای اجرای قطعه کد بالا با فرض نامگذاری فایل کد به s3_delete_bucket_lifecycle_configuration.go میتوان از دستور زیر استفاده کرد:
go run s3_delete_bucket_lifecycle_configuration.go BUCKET_NAME