Question

Filter not work in spaces for expiration using "@aws-sdk/client-s3" (nodejs)

When I try setting expiration via nodejs (code below)

import "dotenv-defaults/config";
import { PutBucketLifecycleConfigurationCommandInput } from "@aws-sdk/client-s3";

const s3Client = new S3({
    endpoint: "https://sgp1.digitaloceanspaces.com",
    region: "sgp1",
    credentials: {
      accessKeyId: process.env.ACCESS_KEY,
      secretAccessKey: process.env.SPACES_SECRET
    }
});

const params: PutBucketLifecycleConfigurationCommandInput = {
  Bucket: "maxchat",
  LifecycleConfiguration: {
    Rules: [
      {
        Expiration: {
          Days: 1,
        },
        Filter: {
          Prefix: "oneday/",
        },
        Status: "Enabled",
        ID: "Expiration1Days",
      },
    ],
  },
};

const run = async () => {
  try {
    const data = await s3Client.putBucketLifecycleConfiguration(params);
    console.log("data", data);
  } catch (err) {
    console.log("Error", err);
  }
};

run();

and I try to get my object (file) in other prefix (folder) using nodejs (code below)

// some import ...

export const params: GetObjectCommandInput = {
  Bucket: "<my-space-name>",
  Key: "other-perfix/<my-file>.txt",
};

// Generates the URL.
export const run = async () => {
  try {
    const data = await s3Client.getObject(params); // Adjustable expiration.
    console.log("Contents:", data.Expiration);
    return data;
  } catch (err) {
    console.log("Error", err);
  }
};

run();

and the result (concole.log) is

Contents: {
  '$metadata': {
    httpStatusCode: 200,
    requestId: undefined,
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  AcceptRanges: 'bytes',
  Expiration: 'expiry-date="Tue, 06 Sep 2022 15:03:07 GMT", rule-id="Expiration1Days"',
  LastModified: 2022-09-05T15:03:07.000Z,

// other log....

why my file with prefix “other-prefix” expiration with id “Expiration1Days” ?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel