Python (SDK)
import latitudesh_python_sdk
from latitudesh_python_sdk import Latitudesh
import os
with Latitudesh(
bearer=os.getenv("LATITUDESH_BEARER", ""),
) as latitudesh:
res = latitudesh.object_storage.post_storage_bucket_lifecycle_rules(bucket_id="<id>", data={
"type": latitudesh_python_sdk.PostStorageBucketLifecycleRulesType.LIFECYCLE_RULES,
"attributes": {
"name": "delete-old-logs",
"prefix": "logs/",
"expiration_days": 30,
},
})
# Handle response
print(res)package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.ObjectStorage.PostStorageBucketLifecycleRules(ctx, "<id>", operations.PostStorageBucketLifecycleRulesRequestBody{
Data: operations.PostStorageBucketLifecycleRulesData{
Type: operations.PostStorageBucketLifecycleRulesTypeLifecycleRules,
Attributes: operations.PostStorageBucketLifecycleRulesAttributes{
Name: "delete-old-logs",
Prefix: latitudeshgosdk.Pointer("logs/"),
ExpirationDays: 30,
},
},
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}import { Latitudesh } from "latitudesh-typescript-sdk";
const latitudesh = new Latitudesh({
bearer: process.env["LATITUDESH_BEARER"] ?? "",
});
async function run() {
const result = await latitudesh.objectStorage.postStorageBucketLifecycleRules({
bucketId: "<id>",
requestBody: {
data: {
type: "lifecycle_rules",
attributes: {
name: "delete-old-logs",
prefix: "logs/",
expirationDays: 30,
},
},
},
});
console.log(result);
}
run();curl --request POST \
--url https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/vnd.api+json' \
--data '
{
"data": {
"type": "lifecycle_rules",
"attributes": {
"name": "delete-old-logs",
"enabled": true,
"prefix": "logs/",
"expiration_days": 30
}
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/vnd.api+json'},
body: JSON.stringify({
data: {
type: 'lifecycle_rules',
attributes: {name: 'delete-old-logs', enabled: true, prefix: 'logs/', expiration_days: 30}
}
})
};
fetch('https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'data' => [
'type' => 'lifecycle_rules',
'attributes' => [
'name' => 'delete-old-logs',
'enabled' => true,
'prefix' => 'logs/',
'expiration_days' => 30
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/vnd.api+json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/vnd.api+json")
.body("{\n \"data\": {\n \"type\": \"lifecycle_rules\",\n \"attributes\": {\n \"name\": \"delete-old-logs\",\n \"enabled\": true,\n \"prefix\": \"logs/\",\n \"expiration_days\": 30\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/vnd.api+json'
request.body = "{\n \"data\": {\n \"type\": \"lifecycle_rules\",\n \"attributes\": {\n \"name\": \"delete-old-logs\",\n \"enabled\": true,\n \"prefix\": \"logs/\",\n \"expiration_days\": 30\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "lifecycle_7Rk2Wd38dXnZJ",
"type": "lifecycle_rules",
"attributes": {
"name": "delete-old-logs",
"enabled": true,
"prefix": "logs/",
"expiration_days": 30,
"noncurrent_days": null,
"abort_mpu_days_after_initiation": null
}
}
}Object Storage
Create lifecycle rule
Creates a new lifecycle rule for an object storage bucket. Lifecycle rules automate object expiration based on age.
POST
/
storage
/
buckets
/
{bucket_id}
/
lifecycle_rules
Python (SDK)
import latitudesh_python_sdk
from latitudesh_python_sdk import Latitudesh
import os
with Latitudesh(
bearer=os.getenv("LATITUDESH_BEARER", ""),
) as latitudesh:
res = latitudesh.object_storage.post_storage_bucket_lifecycle_rules(bucket_id="<id>", data={
"type": latitudesh_python_sdk.PostStorageBucketLifecycleRulesType.LIFECYCLE_RULES,
"attributes": {
"name": "delete-old-logs",
"prefix": "logs/",
"expiration_days": 30,
},
})
# Handle response
print(res)package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.ObjectStorage.PostStorageBucketLifecycleRules(ctx, "<id>", operations.PostStorageBucketLifecycleRulesRequestBody{
Data: operations.PostStorageBucketLifecycleRulesData{
Type: operations.PostStorageBucketLifecycleRulesTypeLifecycleRules,
Attributes: operations.PostStorageBucketLifecycleRulesAttributes{
Name: "delete-old-logs",
Prefix: latitudeshgosdk.Pointer("logs/"),
ExpirationDays: 30,
},
},
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}import { Latitudesh } from "latitudesh-typescript-sdk";
const latitudesh = new Latitudesh({
bearer: process.env["LATITUDESH_BEARER"] ?? "",
});
async function run() {
const result = await latitudesh.objectStorage.postStorageBucketLifecycleRules({
bucketId: "<id>",
requestBody: {
data: {
type: "lifecycle_rules",
attributes: {
name: "delete-old-logs",
prefix: "logs/",
expirationDays: 30,
},
},
},
});
console.log(result);
}
run();curl --request POST \
--url https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/vnd.api+json' \
--data '
{
"data": {
"type": "lifecycle_rules",
"attributes": {
"name": "delete-old-logs",
"enabled": true,
"prefix": "logs/",
"expiration_days": 30
}
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/vnd.api+json'},
body: JSON.stringify({
data: {
type: 'lifecycle_rules',
attributes: {name: 'delete-old-logs', enabled: true, prefix: 'logs/', expiration_days: 30}
}
})
};
fetch('https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'data' => [
'type' => 'lifecycle_rules',
'attributes' => [
'name' => 'delete-old-logs',
'enabled' => true,
'prefix' => 'logs/',
'expiration_days' => 30
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/vnd.api+json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/vnd.api+json")
.body("{\n \"data\": {\n \"type\": \"lifecycle_rules\",\n \"attributes\": {\n \"name\": \"delete-old-logs\",\n \"enabled\": true,\n \"prefix\": \"logs/\",\n \"expiration_days\": 30\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.latitude.sh/storage/buckets/{bucket_id}/lifecycle_rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/vnd.api+json'
request.body = "{\n \"data\": {\n \"type\": \"lifecycle_rules\",\n \"attributes\": {\n \"name\": \"delete-old-logs\",\n \"enabled\": true,\n \"prefix\": \"logs/\",\n \"expiration_days\": 30\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "lifecycle_7Rk2Wd38dXnZJ",
"type": "lifecycle_rules",
"attributes": {
"name": "delete-old-logs",
"enabled": true,
"prefix": "logs/",
"expiration_days": 30,
"noncurrent_days": null,
"abort_mpu_days_after_initiation": null
}
}
}Was this page helpful?
⌘I