1

I want to add a lifecycle policy to my existing s3 bucket (using serverless) which deletes all the folders inside my s3 bucket.I have written the code in the serverless.yml.When I am trying to deploy my code i am getting -

Additional stack resources updated failed (UPDATE_ROLLBACK_COMPLETE).

so i checked into cloudformation stacks , i am getting message that my bucket already exists -

my_bucket_name already exists

Resource update cancelled

The following resource(s) failed to create: [my_bucket_name]

I am not sure why am i getting this , my s3_bucket code looks like this -

custom:
    additionalStacks:
      ressources:
        Resources:
          MyS3TBucket:
            Type: AWS::S3::Bucket
            Properties:
              BucketName: my_bucket
              LifecycleConfiguration:
                Rules:
                  - Status: Enabled 
                    ExpirationInDays: 30

This is not my entire s3 code but a small part of it which is required in this post. Before adding lifecycle configuration everything was working fine. Any help would be appreciated , Thank you

geek
  • 89
  • 2
  • 10

1 Answers1

0

As the error suggests:

my_bucket_name already exists

The bucket that you want to create already exists. If its yours, you have to delete it before you can re-create it. If not, bucket names must be globally unique. This means that maybe some other AWS user has already created a backed with the same name as yours. In this case you must ensure that the back name is absolutely unique, which is often done by adding some random postfix, e.g.:

MyS3TBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: my_bucket-489d939239dd3
        LifecycleConfiguration:
          Rules:
            - Status: Enabled 
              ExpirationInDays: 30
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • The bucket already exists , I only had made it, now I just want to add lifecycle policy to my bucket, thats why i have just added "LifecycleConfiguration:" part of code to my existing bucket. The name of the bucket is unique – geek Oct 21 '21 at 05:45
  • @PRANAVKAKADE Sadly you can't do this. You have to manually delete the bucket that you created, and let it be re-created using cloudformation. The only other options are to [import](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import.html) your per-existing bucket to cloudformation, or use [custom resource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html) to add the policy. – Marcin Oct 21 '21 at 05:48
  • I already have this resource in my custom section, so still its not possible ? – geek Oct 21 '21 at 05:57
  • @PRANAVKAKADE custom resource is totally different then custom section, Please check docs I linked. – Marcin Oct 21 '21 at 06:06
  • @PRANAVKAKADE How did it go? Still unclear what you can do? If so, acceptance of my answer would be appreciated. – Marcin Oct 21 '21 at 23:57
  • yeah still not sure , what exactly has to be done , Thanks for your help , i really appreciate it. – geek Oct 22 '21 at 04:31
  • @PRANAVKAKADE If my help was useful, acceptance of the answer would be appreciated. Have to click a "tick" button under up/down votes of the answer. I would suggest trying to make a custom resource on your own and making new question for that. – Marcin Oct 22 '21 at 04:32
  • hey , yes i did , i dont have 15 reputation thats why its not visible but it has been recorded. yes i am exploring custom resource , thanks for suggesting. – geek Oct 22 '21 at 05:19
  • @PRANAVKAKADE For accepting, no reputation is needed. Its a button under upvote/downvote. – Marcin Oct 22 '21 at 05:20
  • oh got it , sorry i am new to stackoverflow , didnt know this – geek Oct 22 '21 at 05:38
  • @PRANAVKAKADE No problem. You also get points for accepting answers:-) – Marcin Oct 22 '21 at 05:40
  • 1
    Yeah i got it , thanks means a lot :) – geek Oct 22 '21 at 05:54