By using AWS re:Post, you agree to the Terms of Use

How to append timestamp to s3 bucket name in suffix using cloudformation template?


I am using AWS cloud formation template for creating resources in my AWS account. Now, in order to make the s3 bucket name unique, I want to add the current timestamp to the suffix of s3 bucket name so that it'll be unique everytime. Is there any way to carry this out using cloud formation template or lambda functions? If there is a way, please let me know. Thanks in advance.

2 Answers

One way to do it is to write your own CloudFormation Macro or use an existing one. Have a look at the example Macros at to see what's possible. The PyPlate macro there may suit your needs without you having to write a new Macro.

Another option is the write a Custom Resource. If you do, I strongly recommend making use of something like crhelper ( - it makes it so much easier.

answered a month ago

I would not recommend creating a custom resource for this at all. Indeed a macro is more appropriate for what you are trying to do. But I would still recommend to stick to what CloudFormation "native" has to offer in this particular use-case for the bucket name: have a parameter for the bucket name. Personally though, I much prefer to to add region and account number with the native functions. The only parameter you need is a prefix (or suffix) to the bucket name. Hope this helps :)

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions