sst icon indicating copy to clipboard operation
sst copied to clipboard

feat(bucket): add lifecycle config to built-in bucket component

Open mkilp opened this issue 1 month ago • 8 comments

Hi guys,

initially i just thought about adding docs with an example (https://github.com/sst/sst/pull/6206) but after thinking some more I feel like this is such a common use case that it warrants first party support.

This PR adds just that.

In this basic version I expose expiration and filters, not the full blown pulumi lifecycle rules for simplicity and ease of configuration.

Happy to expand / iterate on everything if you think its required.

Cheers ✌️

mkilp avatar Nov 03 '25 17:11 mkilp

This is code I've had to repeat over and over through multiple projects, so I'm really pumped this can be part of SST now.

dragonautdev avatar Nov 04 '25 09:11 dragonautdev

note: if we merge this we should probably close #4941 and #6206

vimtor avatar Dec 03 '25 15:12 vimtor

Agreed, at first i wanted a proper doc example but then decided to just add first party support. Hope we can get it merged soon once the SST team figures out the maintainer stuff.

mkilp avatar Dec 03 '25 15:12 mkilp

@mkilp checking the API design you proposed and i'm wondering the following changes:

new sst.aws.Bucket("Example", {
  lifecycle: [
    prefix: "/tmp",
    expiresIn: "7 days",
    expiresAt: "2025-12-12",
  ]
});

the changes:

  1. array instead of an object for defining multiple rules
  2. rename filterPrefix to prefix
  3. enabled is true by default
  4. replace expires by top level properties:
  5. expiresIn uses common SST syntax for defining duration (could also be passed as "12 months" using the duration.ts utility)
  6. expiresAt as top level property
  7. expiredObjectDeleteMarker removed since people knowing what that is are probably going to need the Pulumi construct anyway

what do you think?

vimtor avatar Dec 03 '25 17:12 vimtor

@mkilp checking the API design you proposed and i'm wondering the following changes:

new sst.aws.Bucket("Example", {
  lifecycle: [
    prefix: "/tmp",
    expiresIn: "7 days",
    expiresAt: "2025-12-12",
  ]
});

the changes:

  1. array instead of an object for defining multiple rules
  2. rename filterPrefix to prefix
  3. enabled is true by default
  4. replace expires by top level properties:
  5. expiresIn uses common SST syntax for defining duration (could also be passed as "12 months" using the duration.ts utility)
  6. expiresAt as top level property
  7. expiredObjectDeleteMarker removed since people knowing what that is are probably going to need the Pulumi construct anyway

what do you think?

@vimtor appreciate the feedback, I asked the exact same thing in the discord if there is a standard api. I really like your proposed changes, I'll get that in.

mkilp avatar Dec 03 '25 18:12 mkilp

@vimtor just changed the api and made a new union type for the expiration. Hopefully we can get that in now that PRs are being merged!

mkilp avatar Dec 08 '25 15:12 mkilp

one last thing, i'm maybe contradicting myself but i've noticed that the bucket already uses filterPrefix and filterSuffix for the notifications:

Image probably we should use those names and their description to stay consistent

Looking at pulumi AWS does not allow suffixes anymore, so I would be fine with staying with just "prefix"

mkilp avatar Dec 10 '25 14:12 mkilp

@vimtor Comments are all set! Sorry, my VSCode PR review panel really messed with me today.

mkilp avatar Dec 10 '25 16:12 mkilp