1

I wish to rename a file that exists in S3 using CDK. That's pretty much it. The closest thing I found was BucketDeployment and it doesn't work for this purpose. Is there a way to do this, or should I just write a lambda?

Avi Jain
  • 99
  • 1
  • 8
  • 1
    If it is just a file, why not manually rename it? To my understanding CDK is for provisioning resources (IaC). Is renaming a necessary step in your deployment? – Register Sole Jan 19 '22 at 08:19
  • Manual steps, are, a manual touchpoint. Yes, CDK is IAC and I'd like to automate e2e. Further context - I just want to add an extension at the end so that the consumer can understand the file being passed – Avi Jain Jan 19 '22 at 08:21
  • I see. Instead of Lambda, I think it is easier to just create a custom script? https://stackoverflow.com/questions/61715131/aws-cdk-run-external-build-command-in-cdk-sequence – Register Sole Jan 19 '22 at 08:26
  • You can use a step function SDK call to do this. – moltar Jan 19 '22 at 13:27
  • 1
    @AviJain I agree with Allan Chua's answer, but if you still want to go ahead with a pure CDK based approach, you can create a Lambda backed custom resource using the [custom resources](https://docs.aws.amazon.com/cdk/api/v1/docs/custom-resources-readme.html) module. You might already know this since you mentioned Lambda in your question. – Kaustubh Khavnekar Jan 19 '22 at 17:56
  • For anybody else looking at this, yep, the custom resource thing works, and one can make a SDK call with it (S3 in this case, don't need to "write" a lambda) – Avi Jain Jan 24 '22 at 23:04

1 Answers1

0

AWS CDK's main purpose is to provision infrastructure. Managing the data stored on those infrastructure is an entirely different story.

Deploying Updates to Static Site
If the goal of this rename operation is for deployment purposes, I would suggest to just use AWS CLI, this makes release process much simpler with less risk as the underlying infrastructure is not at risk of unintentional modifications / bugs in the updates made on the infrastructure's CDK templates.

This option makes mounting on a CI/CD pipeline much more simpler too!

Managing application data If the goal of this rename is to manage application data, I would suggest using AWS SDK for your language of choice.

Layering automation is a subtle best practice! Using these automation tools for the right goal / use-cases can empower us to deliver changes quicker to customers!

Allan Chua
  • 9,305
  • 9
  • 41
  • 61